[DllImport("user32.dll")] static extern void mouse_event(int flags, int dX, int dY, int buttons, int extraInfo); const int MOUSEEVENTF_MOVE = 0x1;//模拟鼠标移动 const int MOUSEEVENTF_LEFTDOWN = 0x2;// const int MOUSEEVENTF_LEFTUP = 0x4; const int MOUSEEVENTF_RIGHTDOWN = 0x8; const int MOUSEEVENTF_RIGHTUP = 0x10; const int MOUSEEVENTF_MIDDLEDOWN = 0x20; const int MOUSEEVENTF_MIDDLEUP = 0x40; const int MOUSEEVENTF_WHEEL = 0x800; const int MOUSEEVENTF_ABSOLUTE = 0x8000; public static void MouseMove(int x,int y) { //控制鼠标移动到坐标x * 65536 / 1920, y * 65536 / 1080这个绝对位置上。1920和1080是电脑屏幕的分辨率 //分辨率要根据自己的电脑设置正确,不然获取到的坐标不准确。 mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, x * 65536 / 1920, y * 65536 / 1080, 0, 0); Thread.Sleep(100); } public static void MouseClick() { //鼠标在原地左键点击一次(点下和松开) mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); Thread.Sleep(100); mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); }

浙公网安备 33010602011771号