Search code examples
x11xlibxorgxcb

If while press and holding grabbed key, other keys are also "grabbed"


I have grabbed a key with XGrabKey:

int mods = 0;
bool ownerevents = true;
XGrabKey(display, MY_KEYCODE, mods, rootwin, ownerevents, GrabModeAsync, GrabModeAsync);

It succesfully grabs the key. In my example MY_KEYCODE is for that of key b. So now my event loop is picking up only if I press the b key. HOWEVER if I hold down the b key and then press other keys, those are also getting reported to my event loop and are also being blocked, so "grabbed" temporarily. I thought to try XAllowEvents in the KeyPressed part, but it is not working.

Does anyone have any ideas on how to get other keys, while my grabbed key is held, to succesfully pass through ungrabbed?


Solution

  • It is not possible to do what your want. Once the grabbed key is pressed, the entire keyboard is grabbed until the key is released.

    If you want programmatically globally replace a keysym bound to a key, this is normally done with key remapping. See XChangeKeyboardMapping and XkbChangeMap.

    If you just want remap a key permanently and don't care how it's done, you probably want to write/modify a config file and not bother with programming at all. See xmodmap and xkbcomp.