【C#学习笔记】鼠标控制
using System; using System.Runtime.InteropServices; using System.Windows.Forms; namespace ConsoleApplication1 { class Program { public struct POINT { public int x, y; } 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_MOVE = 0x1; [DllImport("user32.dll")] public static extern int GetCursorPos(ref POINT p); [DllImport("user32.dll")] public static extern int SetCursorPos(int x, int y); [DllImport("user32.dll")] public static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); static void Main(string[] args) { POINT p=new POINT(); GetCursorPos(ref p); Console.WriteLine(p.x + " " + p.y); SetCursorPos(0, 0); mouse_event(MOUSEEVENTF_RIGHTDOWN, p.x, p.y, 0, 0); mouse_event(MOUSEEVENTF_RIGHTUP, p.x, p.y, 0, 0); Console.Read(); } } }