[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
const int MOUSEEVENTF_MOVE = 0x0001;
const int MOUSEEVENTF_LEFTDOWN = 0x0002;
const int MOUSEEVENTF_LEFTUP = 0x0004;
const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
const int MOUSEEVENTF_RIGHTUP = 0x0010;
const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
const int MOUSEEVENTF_MIDDLEUP = 0x0040;
const int MOUSEEVENTF_ABSOLUTE = 0x8000;
以下是调用代码:
mouse_event(MOUSEEVENTF_MOVE, , , , );
mouse_event(MOUSEEVENTF_LEFTDOWN, , , , );
mouse_event(MOUSEEVENTF_LEFTUP, , , , );
上面代码的移动鼠标会有点问题,这个不是绝对的坐标。以下代码是绝对坐标
声明:
[DllImport("User32.dll")]
private static extern bool SetCursorPos(int x, int y);
调用:
SetCursorPos(, );