我使用How to simulate Mouse Click in C#?中的以下代碼,我發現它不起作用。下面是代碼:爲什麼當我告訴它時鼠標不會點擊?
[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);
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()
{
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 882, 554, 0, 0);
}
private void button1_Click(object sender, EventArgs e)
{
DoMouseClick();
}
我也試圖與mouse_event(MOUSEEVENTF_LEFTDOWN & MOUSEEVENT_LEFTUP...
但仍沒有運氣更換mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENT_LEFTUP...
。其他人已經取得了成功...我爲什麼不是?
您正在運行的是哪個版本/位深度的操作系統? – RQDQ 2012-07-13 19:39:49
MOUSEEVENTF_LEFTDOWN和MOUSEEVENTF_LEFTUP在一個調用中? – 2012-07-13 19:42:26
@RQDQ Windows 7 – 2012-07-13 19:42:53