Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

listening for key/mouse events

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

like image 910
Stas Jaro Avatar asked Nov 04 '22 19:11

Stas Jaro


1 Answers

The window manger will track the focus and direct input according to its configuration. If your window manager decides to send input to a different program because it is enforcing a change of focus, you are out of luck.

While the program lacks focus, if it were able to obtain the mouse and keyboard events, it would be a major security hole. Basically any small unnoticeable background program could spy on the entire system, possibly even stealing passwords in the process.

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

Another technique (by no means guaranteed) is for the program to detect minimization events, and to request focus within a minimization event handler. Note that doing so would probably (If I were writing a window manager) unminimize the window.

like image 91
Edwin Buck Avatar answered Nov 12 '22 16:11

Edwin Buck