Aqua keysyms

Mac keyboards have keys labelled "control", "alt", and "⌘" (that last one looks, as it leaves my keyboard, like a four-leaf clover, is represented by U+2318, and is often called the command key or the apple key) both to the left and right of the spacebar.

The following script displays the Tk representation ( keysyms ) of these keys

label .l
pack .l
bind . <KeyPress> {.l configure -text %K}

For each key in turn, the label says:

  • control == Control_L
  • alt == Meta_L
  • ⌘ == Alt_L

Yes, really. Where it gets utterly confusing, however, is when the keys are used (as they almost always are) as modifiers.

label .m
pack .m
bind . <Command-g> {.m configure -text "command g"}
bind . <Option-g> {.m configure -text "alt g"}
bind . <Control-g> {.m configure -text "control g"}

As a final note, it is useful to know that the bindings are case-sensitive; in other words, <Command-g> and <Command-G> are separate bindings, the latter perhaps more easily being understood as Command and Shift and g together.

As a postscript, it is unfortunate that whilst Windows uses the Control key as a modifier for the most common operations, e.g. Ctrl-C, Ctrl-X and Ctrl-V for copy, cut and paste respectively, MacOS X uses the ⌘ (command) key in the same situations. Thus it is necessary for a cross-platform application that wishes to adhere to native conventions to define platform dependent bindings.

-- Alastair Davies 2005/07/25

JH: I simply manage this with code like:

if {[tk windowingsystem] eq "aqua"} {
    set control "Command"
    set ctrl    "Command-"
} elseif {[tk windowingsystem] eq "win32"} {
    set control "Control"
    set ctrl    "Ctrl+"
} else {
    set control "Control"
    set ctrl    "Ctrl-"
$menu add command -label "Do Something" -accelerator "${ctrl}d"
bind $something <${control}d> { # do something ... }

See also