I'm still fiddling around with interpreting keyboard input.  I have this
little key reader script:

    import gtk

    def check_key(widget, evt):
        print "state (%d, %d) : <" % (evt.state, evt.keyval),
        for i in xrange(21):
            state = evt.state & 1 << i
            if state:
                print gtk.GDK.GdkModifierType.names[state],
        print ">", gtk.GDK.GdkKeySym.names[evt.keyval]
        return gtk.TRUE

    def _test():
        window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL)
        window.set_title("title")
        window.connect("destroy", gtk.mainquit)

        b = gtk.GtkButton(label="Type here")
        b.set_usize(200, 200)
        b.connect("key-press-event", check_key)
        b.connect("clicked", gtk.mainquit)
        window.add(b)
        b.grab_focus()

        window.show_all()
        gtk.mainloop()

    if __name__ == "__main__":
        _test()

which prints out the event's state and keyval, then a printable version of
them.  Output looks like

    state (0, 65513) : < > Alt_L
    state (64, 102) : < MOD4_MASK > f
    state (0, 65514) : < > Alt_R
    state (64, 102) : < MOD4_MASK > f
    state (0, 65407) : < > Num_Lock
    state (16, 102) : < MOD2_MASK > f
    state (16, 65407) : < MOD2_MASK > Num_Lock
    state (0, 102) : < > f

What's confusing me is that the Gtk 2.0 docs say that <alt> is an alias for
<mod1>.  On my laptop at least (Dell 7500 running Mandrake 8.0 and XFree86
4.0.3, patch level 7mdk), I see the following correspondence between keys
and modmask bits:

    Alt_L        MOD4
    Alt_R        MOD4
    Num_Lock     MOD2
    Scroll_Lock  MOD5

Who's right?  The relevant bit of the docs is in the "Key bindings" section
of

    http://developer.gnome.org/doc/API/2.0/gtk/gtk-resource-files.html

I haven't found anything that generates the other MOD bits on my laptop.
Someone (Sawfish?) intercepts the Windows keypress and pops up a menu.  I
haven't been able to figure out how to turn that off.  Is the correspondence
between keys and mask bits more tenuous than the documentation suggests?  If
so, it looks like I will have to track modifier key presses and maintain my
own modifier key state.

On a side note, are there some publically browsable examples of Gtk rc
files?

Thx,

-- 
Skip Montanaro ([EMAIL PROTECTED])
(847)971-7098

_______________________________________________
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list

Reply via email to