[pygtk] Capturing all mouse/keyboard events

Martin Dengler martin at martindengler.com
Mon Jun 2 09:05:05 WST 2008


Hi,

Does anyone happen to have any tips for writing a pygtk application on
linux that can receive all mouse & keyboard events?  See [1] for some
use cases (they're just proof-of-concept) and [2,3] for some failed
attempts.

pygtk bug #156948[4] seems to be a really annoying one, if my
assumption (that gdk's root window really sees all X events[5]) is
correct.

Thanks,
Martin

1. http://lists.laptop.org/pipermail/sugar/2008-May/006202.html

2.
import gtk
import gtk.gdk

w = gtk.Window()
x = gtk.gdk.get_default_root_window()

x.set_events(gtk.gdk.KEY_PRESS_MASK |
             gtk.gdk.POINTER_MOTION_MASK |
             gtk.gdk.BUTTON_PRESS_MASK |
             gtk.gdk.SCROLL_MASK)

def filter_cb(event, data=None):
    print 'me again7', event.type, event, data
    return gtk.gdk.FILTER_CONTINUE

x.add_filter(filter_cb, 'passthisforward')

gtk.main()

3.
import gtk
import gtk.gdk

w = gtk.Window()
x = gtk.gdk.get_default_root_window()

x.set_events(gtk.gdk.KEY_PRESS_MASK |
             gtk.gdk.POINTER_MOTION_MASK |
             gtk.gdk.BUTTON_PRESS_MASK |
             gtk.gdk.SCROLL_MASK)

def filter_cb(event, data=None):
    print 'me again9', event.type, event, data
    gtk.main_do_event(event)

r = gtk.gdk.event_handler_set(filter_cb, None)

w.show()
gtk.main()


4. http://bugzilla.gnome.org/show_bug.cgi?id=156948

5. If it's good enough for metacity:
http://osdir.com/ml/gnome.devel/2005-04/msg00014.html and metacity's
src/ui/ui.c:75-85
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20080602/cb64f9fa/attachment.pgp


More information about the pygtk mailing list