Updated 2008-01-26 03:54:46 by fisheggs

http://www.purl.org/tcl/home/man/tcl8.4/TkCmd/keysyms.htm describes what key symbol values can be used with bind (any other commands?).

[What is a key symbol?]

KeySyms on platforms other than X11 may contain some answers.

Open a wish session and type
  bind . <KeyPress> {puts %K}

Then press any key or key combination to learn the keysym for your desired key binding.

A Tkinter correspondent:
    from Tkinter import *

    class Output(Label):
        def printkey(self, event):
            self.config(text=event.keysym)

    root = Tk()
    label = Label(root, text='Press a key...')
    output = Output(root, takefocus=1)
    label.pack()
    output.pack()
    output.focus()
    output.bind('<KeyPress>', output.printkey)
    root.mainloop()

(Things are apparently so much simpler in Tcl/Tk.)

fisheggs 2008-01-26 To be fair, you're comparing an apple to an Orange Glazed Coffee Cake. So this is the Deep Dish Apple Pie version of the tcl example.
    package require snit

    ::snit::widgetadaptor Output {
        constructor {args} {
            installhull using label
            $self configurelist $args
        }
        method printkey {event} {
            # I really should have created a ::snit::type that collected all
            # the event values and made them available as instance variables
            # and passed that in here, but to keep it simple....
            $self config -text $event
        }
        delegate method * to hull
        delegate option * to hull
    }

    label .label -text "Press a key..."
    Output .output -takefocus 1
    pack .label
    pack .output
    focus .output
    bind .output <KeyPress> {.output printkey %K}

Is there any way to use accented characters (as used in many European languages) in bindings? I want, for example, Alt-e' (meant to be Alt pressed with an accented e) to be bound to a command. -- CLN 2001-06-11

Peter Lewerin 2001-06-30:
 bind . <Alt-Key-eacute> ...

would seem to do what you want, but possibly only if you actually have a é key to press. At least for me, characters composed with dead keys don't fire the bindings, but character keys (e.g. adiaeresis on my keyboard) do.

[Distinguish keysyms and key codes.]

Mo Dejong included in the Tk test suite keypress-pertinent code. He advises, "See the following procs in tk/tests/event.test:

_init_keypress_lookup _keypress_lookup _keypress _keypress_string

With these commands you can do the following:
    _keypress_string $w HELLO\n

This will generate a keypress for each letter followed by an event for the return key."

See also keysyms for Tcl and Cross platform keysyms

Tk syntax help - Arts and crafts of Tcl-Tk programming

[ Category Characters ]