如何使用Python Xlib监视鼠标事件而不是捕获它们? [英] How can I monitor mouse events with Python Xlib instead of capture them?

查看:320
本文介绍了如何使用Python Xlib监视鼠标事件而不是捕获它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Python中的Xlib来监视和过滤鼠标事件。

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)

哪个不起作用或使用RECORD扩展名到Xlib,我无法弄清楚它是如何工作的。

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

推荐答案

答案似乎是使用Xlib与REC ORD,结果可以在这里看到:
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

这篇关于如何使用Python Xlib监视鼠标事件而不是捕获它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆