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

问题描述 投票:0回答:1

我需要通过C#应用程序使用SendMessage或Post Message对另一个基于windows的应用程序进行左键单击,右键单击和双击.我能够使用FindWindow()方法找到窗口句柄,现在我需要像左键单击(给定的x,y位置),右键单击(给定的x,y位置)和双击(传递给定的x,y位置)这样发送post消息另一个应用程序。请帮助我。谢谢你的帮助。

c# sendmessage postmessage sendinput
1个回答
1
投票

你可以使用我从一个网站上偷来的这段代码。此处. 被偷了 此处.

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
    }
© www.soinside.com 2019 - 2024. All rights reserved.