Linux上按键模拟的问题(Ubuntu 18)
Problem with Keypress simulation on Linux (Ubuntu 18)
我正在制作一个业余爱好项目,它基本上是一个非常旧的闪光游戏的机器人,鼠标移动和点击正常工作,但是所有钥匙按下都使操作系统滞后/口吃和有时停止听所有键盘输入,即真实或假货。
我开始仅使用XTEST的Xlib,但没有起作用,所以我尝试了Xsendevent而不是XTEST,但是所有症状都保持不变,因此最后一次尝试是XDO,这给出了更好的结果,但仍然冻结了OS。
这是我要使用的当前片段来模拟按键:
//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
,绘制事件绘制了所需的信息,它是另一个对象,没有在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
也可以用另一个键替换按键,例如,如果要用backspace替换d,则可以尝试此
xdotool key D BackSpace
您可以在线阅读完整的GUID,也可以使用此工具编写脚本并在许多不同的情况下使用它。您也可以将其用于远程连接。
我希望这对您的小问题有所帮助。
使用evdev
是Linux特定选项。
这是一个更简单的解决方案,因为您只需要打开正确的文件并写入它。
看看这个类似的问题,看看如何开始。
- 在Ubuntu 16.04上安装Cilk时出现问题
- 无法安装 R 包 "nloptr"(Ubuntu 16.04 上的 R3.6.2) - C++编译器问题
- 使用 ubuntu 终端在 c++ 上运行线程类的问题
- OBJ 文件C++与 ubuntu 问题
- 在 Ubuntu 16.04 LTS 上使用 c++ 编译问题?
- 编译问题与 Ubuntu Linux
- Ubuntu 下的 Cmake 和 Intel IPP 的编译问题
- 如何解决我在 Ubuntu 19.04 下使用 GLFW 时遇到的这个编译问题?
- wxWebView在Ubuntu上的编译问题
- 加密蛋白使编译问题Ubuntu
- Linux上按键模拟的问题(Ubuntu 18)
- 使用 ubuntu Linux 的 c++ 文件重定向和编码问题
- 在 ubuntu 的 shell 上编译 cpp 程序时出现问题
- 在Ubuntu中与G 链接的问题
- 在Ubuntu中构建OpenCV 3.1.0的问题
- 我正在尝试运行CUDA示例,但是我在Ubuntu 16.04 Lts上的OpenGL(libglew.a)有问题
- Ubuntu 13.10 C++ OpenGL GLUT - 链接问题 - 未定义对"glClearColor"的引用
- 在 Ubuntu 中使用 OpenSSL 的链接问题
- 使用CMake问题链接Boost(Ubuntu 14.04)
- UBUNTU C 的 USB 到串行通信问题