Listening for key / mouse events

Is it possible to listen for key and mouse events without the user selecting gui? I want to make a program that runs in the background without gui and responds to user interaction, such as clicking ctrl-t.

+5
source share
1 answer

The window operator will track focus and direct input according to its configuration. If your window manager decides to send input to another program because it provides a focus change, you're out of luck.

While the program lacks focus, if it could receive mouse and keyboard events, this would be a serious security hole. In principle, any small inconspicuous background program can track the entire system, possibly even stealing passwords in this process.

Your only hope is to find an option in your window manager that will allow you to minimize the program without changing focus. Of course, everything you type will go only according to the minimized program (and does not affect the rest of the system).

Another method (by no means guaranteed) is a program for detecting minimization events and requesting focus in the minimization event handler. Note that doing this is possible (if I were writing a window manager) unminimize the window.

+2
source

All Articles