How to send key event to application using XCB?

2019-03-19 03:42发布

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

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

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

标签: c++ c x11 xcb
1条回答
【Aperson】
2楼-- · 2019-03-19 04:19

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);

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

查看更多
登录 后发表回答