前台鼠标点击
前台点击会占用鼠标操作,过程可见,且要求窗体在最顶层;
[DllImport("user32.dll", EntryPoint = "SetCursorPos")] private static extern int SetCursorPos(int x, int y); [DllImport("user32.dll", EntryPoint = "mouse_event")] private static extern int Mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); private static readonly int MOUSEEVENTF_MOVE = 0x0001; private static readonly int MOUSEEVENTF_LEFTDOWN = 0x0002; private static readonly int MOUSEEVENTF_LEFTUP = 0x0004; private static readonly int MOUSEEVENTF_ABSOLUTE = 0x8000; /// <summary> /// 前台点击 /// </summary> /// <param name="x">横坐标</param> /// <param name="y">纵坐标</param> public static void MouseClickHere(int x, int y) { //1920和1080为屏幕分辨率,可根据情况调整 Mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, (x) * 65535 / 1920, (y) * 65535 / 1080, 0, 0); Mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); }
后台鼠标点击
后台点击不会占用鼠标操作,过程不可见,需传入窗体句柄作为参数;
您暂时无权查看此隐藏内容!
评论前必须登录!
注册