我开始只在XTests中使用XLib,但是没有成功,所以我尝试了XSendEvent而不是XTests,但是所有的症状都没有改变,所以最后一次尝试是使用XDO,结果更好,但是仍然冻结了操作系统。
这是我试图用来模拟按键的当前片段:
//Constructor
CheatCore::CheatCore() {
xdo_t x = xdo_new(NULL);
Window *list;
xdo_search_t search;
unsigned int nwindows;
memset(&search, 0, sizeof(xdo_search_t));
search.max_depth = -1;
search.require = xdo_search::SEARCH_ANY;
search.searchmask = SEARCH_CLASS | SEARCH_ONLYVISIBLE;
search.winclass = "Chrome";
int id = xdo_search_windows(x, &search, &list, &nwindows);
qDebug() << nwindows;
if(!nwindows){
qDebug() << "Chrome not found";
return;
}
w = list[0];
//I have to call activate twice to really bring it forward, I suspect that its
//because I use a transparent "overlay" that show stats for the cheat and it is set as Aways on top
//(i used Qt to set it to not get any Events)
xdo_activate_window(x,w);
xdo_activate_window(x,w);
}
//there is a function that executes every second to check if a pixel color has changed,
//if so, then the SendKey is called to Reload weapon magazine pressing the "space" key
void CheatCore::SendKey(){
xdo_activate_window(x,w);
xdo_activate_window(x,w);
xdo_send_keysequence_window(x, w, "space", 500);
}
我使用一个透明的覆盖来显示bot状态,只显示一些数字,这是一个使用Qt创建的小部件,即
AlwaysOnTop
而paint事件绘制了所需的信息,它是另一个对象,在
CheatCore
,但这是用于绘制透明窗口并忽略事件的窗口标志。
setWindowFlags(Qt::WindowTransparentForInput | Qt::FramelessWindowHint |
Qt::WindowStaysOnTopHint);
setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_TransparentForMouseEvents);
另外,我试图找到一种Qt方式来模拟鼠标/键盘输入,但我没有找到任何解决方案来发送事件到其他窗口,如果有可能实现这一点将是伟大的!
我正在尝试自动化的游戏叫做“风暴屋”
如果感兴趣,请点击在线回购链接:
link
你能帮我做这个吗?谢谢您!
使用VGA和Nvidia驱动程序的Ubuntu 18.10(如果它可能影响xserver)