[pygtk] catching all keyboard/mouse events

m.c.wilkins at massey.ac.nz m.c.wilkins at massey.ac.nz
Mon Nov 22 08:31:33 WST 2010


Hi,

> Maybe this post will help you a bit:
> http://www.mail-archive.com/pygtk@daa.com.au/msg19101.html

Yes thank you, it did.  It talks of using keybinder.  Unfortunately
that requires binding a particular key combo to a handler (not just
any key, or mouse).  However I downloaded keybinder and found in the
source that they were just using add_filter on the gtk.gdk.Window.

So that I am using a filter now to accept all events (supposedly).
This is my code:

def wakeup(event):
   if not need_to_do_something:
      return gtk.gdk.FILTER_CONTINUE
   # do stuff
   return gtk.gdk.FILTER_CONTINUE

rootwin = gtk.gdk.get_default_root_window()
rootwin.set_events(gtk.gdk.ALL_EVENTS_MASK)
rootwin.add_filter(wakeup)

The only problem with this is that event.type is always
<enum GDK_NOTHING of type GdkEventType>
and I don't receive all events, keyboard ones don't get through, which
is odd.  However, it does work well enough for me at the moment.

Thanks for your help

Matt



More information about the pygtk mailing list