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 <stdio.h>
#include <stdlib.h>
#include <xcb/xcb.h>
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?
DISPLAY
env var exported maybeXAUTHORITY
also. See similar question here. https://unix.stackexchange.com/q/68054/85046 – Jakub Jindra Feb 10 '20 at 09:27xdotool
's only advantage is that it could be called from shell, where you have to put up with all kind of limitations and quirks. From C you can do much better, eg. handle multipointer/multifocus setups with XGetDeviceFocus() instead of XGetInputFocus(). For xdotool's getactivewindow, look for the EWMH's _NET_ACTIVE_WINDOW property. – Feb 10 '20 at 13:22