如何使用 Python Xlib 监视鼠标事件而不是捕获它们?
我需要在 Python 中使用 Xlib 监视和过滤鼠标事件。
到目前为止,我发现这段代码接收事件,但不传递它们,所以我实际上无法再用鼠标做任何事情。
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()
我发现的替代方案是使用
root.change_attributes(event_mask=X.ButtonPressMask | X.ButtonReleaseMask)
Which 根本不起作用或使用 Xlib 的 RECORD 扩展,我不知道它是如何工作的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
链接已损坏。我认为这是最新的: http://github.com/pepijndevos /PyMouse/blob/master/pymouse/unix.py 第 58 行
The link was broken. I think this is the latest one: http://github.com/pepijndevos/PyMouse/blob/master/pymouse/unix.py Line 58
答案似乎是使用 Xlib 和 RECORD,结果可以在这里看到:
http://github.com/pepijndevos/PyMouse/blob/master/ unix.py#L38
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