欢迎访问!
您的支持是我们不断前行的动力!

C# user32.dll MouseHelper 鼠标前台模拟点击,鼠标后台模拟点击

前台鼠标点击

前台点击会占用鼠标操作,过程可见,且要求窗体在最顶层;

[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);
}

后台鼠标点击

后台点击不会占用鼠标操作,过程不可见,需传入窗体句柄作为参数;

您暂时无权查看此隐藏内容!

以上隐藏内容查看价格为3知识币,请先
提示:网络资源非实物交易,购买后无法退款,请考虑好后再购买!如有疑问,请联系管理员!在此,感谢您的支持!
赞(2) 打赏
转载请注明出处,未注明出处不得转载,蜘蛛侠 » C# user32.dll MouseHelper 鼠标前台模拟点击,鼠标后台模拟点击
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

蜘蛛侠,您身边的爬虫专家!

觉得文章有用就打赏一下文章作者吧

支付宝扫一扫打赏

微信扫一扫打赏