模拟鼠标点击 - 鼠标不动
Simulating Mouseclick - Mouse is not moving
我试过了How to simulate Mouse Click in C#?
public void DoMouseClick(uint X, uint Y)
{
//Call the imported function with the cursor's current position
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
}
我的问题是,点击是在那个点上执行的,我的光标在那个点上而不是在那个点上,我设置了 x 和 y。我的坐标没有错。我也尝试过 x=1 和 y=1.
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool SetCursorPos(int x, int y);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
public const int MOUSEEVENTF_LEFTDOWN = 0x0002;//0x02;
public const int MOUSEEVENTF_LEFTUP = 0x0004;//0x04;
public void Click(int x, int y)
{
Thread.Sleep(2000);
SetCursorPos(x, y);
Thread.Sleep(1000);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Thread.Sleep(1000);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
我试过了How to simulate Mouse Click in C#?
public void DoMouseClick(uint X, uint Y)
{
//Call the imported function with the cursor's current position
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
}
我的问题是,点击是在那个点上执行的,我的光标在那个点上而不是在那个点上,我设置了 x 和 y。我的坐标没有错。我也尝试过 x=1 和 y=1.
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool SetCursorPos(int x, int y);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
public const int MOUSEEVENTF_LEFTDOWN = 0x0002;//0x02;
public const int MOUSEEVENTF_LEFTUP = 0x0004;//0x04;
public void Click(int x, int y)
{
Thread.Sleep(2000);
SetCursorPos(x, y);
Thread.Sleep(1000);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Thread.Sleep(1000);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}