简体   繁体   English

使用 C# 应用程序双击另一个 windows 应用程序

[英]Double Click on another windows Application using C# application

I need to left click, Right click and Double click on another windows based application via C# application using SendMessage or Post Message.我需要使用 SendMessage 或 Post Message 通过 C# 应用程序左键单击、右键单击并双击另一个基于 windows 的应用程序。 I am able to find window handle using FindWindow() method now i need to send/post message another application like left click(given x,y position), right click (given x,y position) and double click (passing given x,y position).我可以使用 FindWindow() 方法找到 window 句柄现在我需要发送/发布消息另一个应用程序,例如左键单击(给定 x,y 位置),右键单击(给定 x,y 位置)和双击(传递给定 x, y 位置)。 Kindly do the help.请帮忙。 Thanks谢谢

You can use this snippet i stole from a here .你可以使用我从这里偷来的这个片段。 Wich was stolen from here .威奇是从这里偷来的。

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

    public class Form1 : Form
    {
       [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
       public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
       //Mouse actions
       private const int MOUSEEVENTF_LEFTDOWN = 0x02;
       private const int MOUSEEVENTF_LEFTUP = 0x04;
       private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
       private const int MOUSEEVENTF_RIGHTUP = 0x10;

       public Form1()
       {
       }

       public void DoMouseClick()
       {
          //Call the imported function with the cursor's current position
          uint X = (uint)Cursor.Position.X;
          uint Y = (uint)Cursor.Position.Y;
          mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
       }

       //...other code needed for the application
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM