linux按键代码,Linux上的按键模拟问题(Ubuntu18)

我开始只在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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值