有谁知道如何在桌面的特定点上执行鼠标点击?我需要一个应用程序来执行鼠标点击本地化在桌面上特定位置的另一个应用程序按钮。
答案 0 :(得分:0)
这适用于WinForms
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
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 void DoMouseClick() {
//Call the imported function with the cursor's current position
int X = Cursor.Position.X;
int Y = Cursor.Position.Y;
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
}
来自http://www.gamedev.net/topic/321029-how-to-simulate-a-mouse-click-in-c/
答案 1 :(得分:0)
您可以查看Coded UI。它的主要目的是在应用程序上执行UI测试,并支持对各种不同应用程序框架(WPF,WinForms,VB等)的编程访问。