I need to know on Linux when a user press a key or use a button of his
mouse even when my app is not in focus. I only successed in writing a program that listen to an event when the window is in focus using xSelectInput.
The problem is that I can have these events only if I make a client
window which have the focus on it [I use these maks
XSelectInput(display, win, KeyPressMask |ButtonPressMask); ]

If I ask directly for the main root window events
[XSelectInput(display, root_window, KeyPressMask |ButtonPressMask);] I
get an error msg.

how can I listen to all keypressed/release events ?

Thanks in advance.