Goal
I want to redirect the keyboard input to different windows depending on the key. Not all the key will be redirected to the same window, I can't use XSetInputFocus
.
First Attempt : XGrabKey
I found that I can grab certain keys and then send an event to the right window. I used XGrabKey like this
XGrabKey( mDisplay(),
XKeysymToKeycode(mDisplay(),XK_F1) ,
AnyModifier ,
RootWindow(mDisplay(), mScreenNum),
false, //Events aren't sent to the focused window
GrabModeAsync,
GrabModeAsync );
It doesn't work for F1 to F4 keys, but it does for F5 and F6. It also doesn't work for some regular keys like e, r and t. There may be others. I need to be able to redirect the Fkeys, so this solution didn't work for me.
Second Attempt : XGrabKeyboard
I tried with XGrabKeyboard, like this
XGrabKeyboard(mDisplay(),
RootWindow(mDisplay(), mScreenNum),
false,
GrabModeAsync,
GrabModeAsync,
CurrentTime);
It works with all the Fkeys, but it created other problems. When the grab keyboard is active I can no longer move the windows with my mouse (it still works if the application move its window), I can't access to context menus and the blinking '|' isn't displayed in typing areas.
Other informations
This problem as already been talked about there, but they didn't find a solution.I am using Lubuntu(LXDE) and not GNOME and I still have the same problem.
The unmap event may give some informations:
When the keyboard is not grabbed and I right click
the context menu is displayed, no unmap event.
When I exit the context menu :
I have 3 unmap events : (I print the name of the window next to Unmap)
Unmap pcmanfm
Unmap pcmanfm
Unmap
When the keyboard is grabbed and I right click
I have just 1 unmap event :
Unmap
It looks like the context menu is unmapped before it is displayed.
What I am asking for
I would like to either:
- Use XGrabKeyboard without side effects
- Use XGrabKey with any key
- Use another fonction that would allow me to redirect keyboard input
Thank you.