开发者

How can I monitor mouse events with Python Xlib instead of capture them?

开发者 https://www.devze.com 2022-12-26 01:00 出处:网络
I need to monitor and filter mouse events with Xlib in Python. So far I have found out that this code receives events, but does not pass them on, so I can\'t actually do anything with the mouse anymo

I need to monitor and filter mouse events with Xlib in Python.

So far I have found out that this code receives events, but does not pass them on, so I can't actually do anything with the mouse anymore.

from Xlib.display import Display
from Xlib import X

display = Display(':0')
root = display.screen().root

root.grab_pointer(True, X.ButtonPressMask | X.ButtonReleaseMask, X.GrabModeAsync, X.GrabModeAsync, 0, 0, X.CurrentTime)

while True:
    print "Event:"
    print display.next_event()

Alter开发者_高级运维natives I found are using

root.change_attributes(event_mask=X.ButtonPressMask | X.ButtonReleaseMask)

Which does not work at all or using the RECORD extension to Xlib, which I can't figure out how it works.


The link was broken. I think this is the latest one: http://github.com/pepijndevos/PyMouse/blob/master/pymouse/unix.py Line 58


The answer seemed to be to use Xlib with RECORD, the result can be seen here: http://github.com/pepijndevos/PyMouse/blob/master/unix.py#L38

0

精彩评论

暂无评论...
验证码 换一张
取 消