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

好久不见. 提交于 2019-12-05 07:26:46

问题


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()

Alternatives 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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/2585647/how-can-i-monitor-mouse-events-with-python-xlib-instead-of-capture-them

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!