As the title states, I'm trying to capture Mouse and Keyboard events with Python-gtk.
I can do this easily with python-xlib with:
self.display = display.Display()
self.screen = self.display.screen()
self.root_window = self.screen.root
self.root_window.grab_pointer(1,
X.ButtonPressMask | X.ButtonReleaseMask | X.Button1MotionMask,
X.GrabModeAsync,
X.GrabModeAsync,
X.NONE, X.NONE,
X.CurrentTime)
self.root_window.grab_keyboard(1,
X.GrabModeAsync,
X.GrabModeAsync,
X.CurrentTime)
I see the analog using gtk.gdk.* functions, but I just can't seem to capture events on the main desktop window. Can this be done?
This is how I was trying to accomplish the task... (ALL_EVENTS_MASK was an act of desperation ;] )
self.root_window = gtk.gdk.get_default_root_window()
self.root_window.set_events(gtk.gdk.ALL_EVENTS_MASK)
gtk.gdk.event_handler_set(self.filter_callback)
gtk.main()
def filter_callback (self, *args):
print args