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.