模拟鼠标按下
[System.Runtime.InteropServices.DllImport("user32")] private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); [System.Runtime.InteropServices.DllImport("user32")] private static extern bool SetCursorPos(int X, int Y); [System.Runtime.InteropServices.DllImport("user32")] private static extern bool GetCursorPos(out Point lpPoint); public enum MouseEventFlags { LEFTDOWNE = 0x00000002, LEFTUP = 0x00000004, MIDDLEDOWN = 0x00000020, MIDDLEUP = 0x00000040, MOVE = 0x00000001, ABSOLUTE = 0x00008000, RIGHTDOWN = 0x00000008, RIGHTUP = 0x00000010 } /// <summary> /// 模拟鼠标按下 /// </summary> /// <param name="lpPoint">鼠标按下的位置</param> public static void simulateDeviceMouseDown(Point lpPoint) { //先释放鼠标 mouse_event((int)(MouseEventFlags.LEFTUP | MouseEventFlags.ABSOLUTE), 0, 0, 0, 0); //将鼠标移动到指定位置 SetCursorPos(lpPoint.X + 5, lpPoint.Y + 5); //在模拟鼠标按下 mouse_event((int)(MouseEventFlags.LEFTDOWNE | MouseEventFlags.ABSOLUTE), lpPoint.X, lpPoint.Y, 0, 0); }