Qt5 模擬鼠標點擊

windows官方說明:https://docs.microsoft.com/zh-cn/windows/win32/api/winuser/nf-winuser-mouse_event?redirectedfrom=MSDN

參考自:https://www.fearlazy.com/index.php/post/168.html

做一個遊戲輔助,使用Windows API鼠標自動在某一個座標點擊。

//頭文件
#include<Windows.h>
#pragma comment(lib, "User32.lib")

QDesktopWidget *desktopwidget = QApplication::desktop();
int desktop_width = desktopwidget->width();  //獲取屏幕分辨率寬度
int desktop_height = desktopwidget->height();  //獲取屏幕分辨率高度
int stronghold_height = desktop_height * 0.68;  //要點擊鼠標的位置在屏幕一定比例的位置
int stronghold_width = desktop_width * 0.9;
::mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, stronghold_width * 65535 / 1366, stronghold_height * 65535 / 768,0 ,0);  //移動到指定位置
::mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);  //按下左鍵
::mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);  //左鍵擡起

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章