I am trying to set up a global hotkey on Linux.
I had initially used x11 (libX11.so
) however I had to do this from a thread. I tried it but the XPendingEvent
and XNextEvent
would eventually crash the app.
So I switched to xcb (libxcb.so.1
). There is no errors, I even check with xcb_request_check
however the event loop is not picking anything up. As soon as I start the loop, I get only one event which looks like this:
{
response_type: 0,
pad0: 10,
sequence: 2,
pad: [620, 2162688, 0, 0, 0, 0, 0],
full_sequence: 2
}
Here is my code, I actually do this in js-ctypes, but I cut down all the stuff to just show simple agnostic as possible code:
conn = xcb_connect(null, null);
keysyms = xcb_key_symbols_alloc(conn);
keycodesPtr = xcb_key_symbols_get_keycode(keysyms, XK_Space);
setup = xcb_get_setup(conn);
screens = xcb_setup_roots_iterator(setup);
screensCnt = screens.rem;
for (var i=0; i<screensCnt; i++) {
rez_grab = xcb_grab_key(conn, 1, screens.data.root, XCB_MOD_MASK_ANY, keycodesPtr[0], XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
rez_err = xcb_request_check(conn, rez_grab);
// rez_err is null
xcb_screen_next(&screens);
}
xcb_flush(conn);
// start event loop
while (true) {
ev = xcb_poll_for_event(conn);
console.log(ev);
if (ev != null) {
free(ev);
}
Sleep(50);
}
console.log(ev)
gives me what I posted above earlier, response_type
of 0
and then forever after that ev
is just null
.
Does anyone know what's up? rez_grab as a raw string is xcb_void_cookie_t(2)
Thanks much
grab_key
so that key has no affect anywhere, except for my hotkey. Its not working though :( I based it on https://mcmap.net/q/429401/-global-alt-space-hotkey-grabbing-weird-keyboard-focus-behaviour/1828637 - but I am in a thread so it might be different. – Seedbedgcc -o grab grab.c -L/usr/X11/lib -lX11 -lstdc++
however it fails for me :( – Seedbedgcc -o grab grab.c -std=gnu99 -lxcb -lxcb-keysyms
, you may have to add-I
and/or-L
flags but no other flags. – Oogenesisgcc mpkey.c -std=gnu99 -lxcb -lxcb-keysyms
after installingsudo apt-get install x11proto-core-dev
andapt-get install libxcb-keysyms1-dev
. Isnt xcb cross flavor? Do you know why its not working on ubuntu? Thanks so much – SeedbedXCB_MOD_MASK_ANY
and this constant works on Debian but not on Ubuntu, which is what I was using to test. I swithced that up to use num lock, caps lock etc and now it works! :) github.com/Noitidart/NativeShot/blob/master/modules/hotkey/… that was very very crazy i had no idea theXCB_MOD_MASK_ANY
constant didnt work on Ubuntu - github.com/Noitidart/System-Hotkey/blob/master/modules/hotkey/… your exact code i tried on ubuntu it didnt work, but worked on debian – Seedbed