如何使用XCB将按键事件发送到应用程序? [英] How to send key event to application using XCB?

查看:456
本文介绍了如何使用XCB将按键事件发送到应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用XCB从另一个程序向某个窗口(当前活动的窗口)发送按键或释放事件?

How can I send a key press or key release event to a window (the currently active window) from another program using XCB?

我发现了一些使用XLib的教程,但是我想使用XCB.

I found some tutorials using XLib, however I would like to use XCB.

我想我将不得不调用xcb_send_event,但是我不知道该如何将其作为参数传递.

I guess I will have to call xcb_send_event, however I have no idea what to pass it as parameters.

推荐答案

您应该能够使用XTEST扩展程序,通过xcb_test_fake_input()函数来伪造到活动窗口的输入.

You should be able to use the XTEST extension to fake input to the active window, using the xcb_test_fake_input() function.

#include <xcb/xtest.h>
...
xcb_test_fake_input(c, XCB_KEY_PRESS, keycode, XCB_CURRENT_TIME, XCB_NONE, 0, 0, 0);
xcb_test_fake_input(c, XCB_KEY_RELEASE, keycode, XCB_CURRENT_TIME, XCB_NONE, 0, 0, 0);

请参见 xcb/demos中的xte程序一个可行的例子.

See the xte program in xcb/demos for a working example.

这篇关于如何使用XCB将按键事件发送到应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆