K
K
ks_ks2012-03-28 16:32:28
linux
ks_ks, 2012-03-28 16:32:28

Intercepting mouse and keyboard events in Gnome?

This solution is taken from here .

<font color="#008000"><strong>from</strong></font>&nbsp;<font color="#0000FF"><strong>Xlib.display</strong></font>&nbsp;<font color="#008000"><strong>import</strong></font>&nbsp;Display<br/>
<font color="#008000"><strong>from</strong></font>&nbsp;<font color="#0000FF"><strong>Xlib</strong></font>&nbsp;<font color="#008000"><strong>import</strong></font>&nbsp;X<br/>
display&nbsp;<font color="#666666">=</font>&nbsp;Display(<font color="#BA2121">&#39;:0&#39;</font>)<br/>
root&nbsp;<font color="#666666">=</font>&nbsp;display<font color="#666666">.</font>screen()<font color="#666666">.</font>root<br/>
root<font color="#666666">.</font>grab_pointer(<font color="#008000">True</font>,&nbsp;X<font color="#666666">.</font>ButtonPressMask&nbsp;<font color="#666666">|</font>&nbsp;X<font color="#666666">.</font>ButtonReleaseMask,&nbsp;X<font color="#666666">.</font>GrabModeAsync,&nbsp;X<font color="#666666">.</font>GrabModeAsync,&nbsp;<font color="#666666">0</font>,&nbsp;<font color="#666666">0</font>,&nbsp;X<font color="#666666">.</font>CurrentTime)<br/>
<font color="#008000"><strong>while</strong></font>&nbsp;<font color="#008000">True</font>:<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008000"><strong>print</strong></font>&nbsp;<font color="#BA2121">&quot;Event:&quot;</font><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008000"><strong>print</strong></font>&nbsp;display<font color="#666666">.</font>next_event()<br/>

This is how this crap works. How does she do it? :)
The problem is that it hangs, bastard ... and until you forcibly end the program ( exit() ) - it is impossible to switch the window to another, or exit from it ... the interception of mouse clicks is carried out properly, but it does not allow you to do anything beyond this window. How to avoid the problem?
A similar situation arises when adding a keyboard using what is written here - the grab_keyboard() method , which is filled with parameters similar to grab_pointer() . Only with the keyboard it turns out even worse - after running the script, it does not respond to pressing at all. Moreover, the terminal window stops responding to mouse clicks. You have to restart the computer.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alternativshik, 2012-03-28
@alternativshik

Try looking xneur sort

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question