key binding running xdotool unexpected behaviour
2
votes
0
answers
281
views
I've programmed a key to run xdotool when it's pressed. But for some unknown reason xdotool is only sending keystrokes when the binded key is released, except when a non-active window is sent the keystrokes with --window, in which case it (as I would like it to do for the active window instead) sends the keystrokes as the binded key is pressed as well as repeatly when held down.
Example code with the issue:
#include
#include
#include
int main() {
xcb_connection_t *connection = xcb_connect(NULL, NULL);
xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data;
xcb_grab_key(connection, 1, screen->root, XCB_NONE, 65, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); // 65=space (on mine at least)
xcb_flush(connection);
xcb_generic_event_t *event;
while ( (event = xcb_wait_for_event(connection)) ) {
switch (event->response_type & ~0x80) {
case XCB_KEY_PRESS: {
// UNCOMMENT ONE OF THE LINES BELOW
// system("xdotool key q"); // only on release :(
// system("xdotool getactivewindow key --window %1 q"); // only on release :(
// system("xdotool key --window 18874376 q"); // (replace 18874376 with one of your window's id, could use 'xdotool getactivewindow') works perfectly for me but only if the specified window is not active :(
break;
}
}
free(event);
}
}
Please note above doesn't work with modifiers on, including Num Lock.
To compile it:
gcc c.c -lxcb
Do you experience the same and how do I get what I want?
Asked by aaa
(217 rep)
Feb 5, 2020, 11:57 AM
Last activity: Feb 9, 2020, 06:34 PM
Last activity: Feb 9, 2020, 06:34 PM