gpt4 book ai didi

c++ - Linux (Ubuntu 18) 上的按键模拟问题

转载 作者:太空宇宙 更新时间:2023-11-04 11:54:32 26 4
gpt4 key购买 nike

我正在做一个业余项目,它基本上是一个非常古老的 flash 游戏的机器人,鼠标移动和点击工作正常,但所有的按键操作都会使操作系统滞后/卡顿,有时会停止收听所有键盘输入,真的还是假的。

我开始仅将 XLib 与 XTests 一起使用,但没有用,所以我尝试了 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);

}

我正在使用透明覆盖层来显示机器人状态,只显示一些数字,它是一个使用 Qt 创建的小部件,它是 AlwaysOnTop 并且绘制事件绘制所需的信息,它是另一个对象并且在 CheatCore 中没有直接影响,但这是用于在透明窗口上绘制并忽略事件的窗口标志。

setWindowFlags(Qt::WindowTransparentForInput | Qt::FramelessWindowHint | 
Qt::WindowStaysOnTopHint);
setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_TransparentForMouseEvents);

我没能理解是什么导致了这种奇怪的行为,会不会是窗口系统?

另外,我试图找到一种模拟鼠标/键盘输入的 Qt 方法,但我没有设法找到任何解决方案来将事件发送到其他窗口,如果有可能实现这一点那就太好了!

我尝试自动化的游戏叫做“Storm the House”

如果感兴趣,这是在线存储库的链接:link

你能帮我完成这项工作吗?谢谢!

关于设置的上下文:Ubuntu 18.10 使用 VGA 和 Nvidia 驱动程序(如果它可能会影响 xserver)

最佳答案

您是否尝试过从命令行使用 xdotool。要使用 xdotool,您需要先安装包。要模拟按键,您可以使用。

xdotool key <key>

例如,如果你想为 X 模拟按键,你可以使用此代码

xdotool key x

或任何其他组合,例如

xdotool key ctrl+f

你也可以用另一个按键代替按键,例如,如果你想用退格键代替 D 键,你可以试试这个

xdotool key D BackSpace 

您可以在线阅读完整的 guid,也可以使用此工具编写脚本并在许多不同的情况下使用它。您也可以将其用于远程连接。

我希望这能帮助你解决你的小问题。

关于c++ - Linux (Ubuntu 18) 上的按键模拟问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54855289/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com