Skip to content

Instantly share code, notes, and snippets.

@pepijndevos
Created April 6, 2010 13:25
Show Gist options
  • Save pepijndevos/357586 to your computer and use it in GitHub Desktop.
Save pepijndevos/357586 to your computer and use it in GitHub Desktop.
from Xlib.display import Display
from Xlib import X
from Xlib.ext import record
from Xlib.protocol import rq
# True if you want to stop events from reaching other apps
capture = True
def record_callback(reply):
data = reply.data
while len(data):
event, data = rq.EventField(None).parse_binary_value(data, display.display, None, None)
print event
display = Display(':0')
root = display.screen().root
if capture:
root.grab_pointer(True, X.ButtonPressMask | X.ButtonReleaseMask, X.GrabModeAsync, X.GrabModeAsync, 0, 0, X.CurrentTime)
ctx = display.record_create_context(
0,
[record.AllClients],
[{
'core_requests': (0, 0),
'core_replies': (0, 0),
'ext_requests': (0, 0, 0, 0),
'ext_replies': (0, 0, 0, 0),
'delivered_events': (0, 0),
'device_events': (X.ButtonPressMask, X.ButtonReleaseMask),
'errors': (0, 0),
'client_started': False,
'client_died': False,
}])
display.record_enable_context(ctx, record_callback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment