您的位置:首页 > 编程语言 > C#

C# 模拟鼠标事件

2014-03-06 09:05 323 查看
#region 模拟鼠标移动
[DllImport("user32")]
public static extern void SetCursorPos(int x, int y);
#endregion
#region 模拟鼠标单击
private static readonly int MOUSEEVENTF_LEFTDOWN = 0x2;    //鼠标左键down事件
private static readonly int MOUSEEVENTF_LEFTUP = 0x4;    //鼠标左键up事件
[DllImport("user32")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
#endregion

//获取鼠标在屏幕的坐标
int x = Control.MousePosition.X;
int y = Control.MousePosition.Y;

SetCursorPos(x, y);//模拟鼠标移动
mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);//模拟鼠标左键down
mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);//模拟鼠标左键up
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C# 鼠标事件