Version 5 of Modifier Keys

Updated 2011-05-04 15:42:45 by KJN

Page still under construction.

Introduction

When using bind to handle keyboard events, Modifier keys can change the effect of a keystroke. This is described on the manual page bind(n) .

The present page describes the effects of Modifier keys on different platforms. This information has been obtained by experimentation with Tcl/Tk 8.5.8. Some results might depend on the specific hardware used: if you get different results, please document this. If you use a different platform or keyboard (e.g. Sun, Space Cadet [L1 ]), please add a section to this page.

PC running Linux

A standard PC keyboard on Linux never applies the modifiers

    Extended
    Meta, M
    Mod3, M3

The PC keyboard's modifier keys on Linux are:

KeyKeyPress %KKeyRelease %KBinding ModifierPE [1]AR [2]%A [3]Notes
ExtendedNot used in Linux.
Num LockNum_LockNum_LockMod2, M2, OptionYM
Scroll LockScroll_LockScroll_LockYNOT a modifier key in Linux.
Caps LockCaps_LockCaps_LockLockYM
Shift (Left)Shift_LShift_LShiftM
Shift (Right)Shift_RShift_RShiftM
Control (Left)Control_LControl_LControl-*
Control (Right)Control_RControl_RControlY-*
"Windows" (Left)Super_LSuper_LMod4, M4YY
"Windows" (Right)Super_RSuper_RMod4, M4YY
Alt (Left)Alt_LAlt_LAltYA binding with modifier Alt is overridden by a binding with modifier Command, Mod1, or M1.
Alt Gr [4]ISO_Level3_Shift??Mod5, M5YMThe event KeyRelease-ISO_Level3_Shift is not recognised: it is reported as KeyRelease-??.

[1] Column PE means "Persistent". If marked "Y", the key is pressed and released to activate the modifier; the modifier is applied to subsequent keystrokes until the modifier key is pressed and released again. If not marked "Y", the key must be held down to activate its modifier; the modifier is applied to subsequent keystrokes until the modifier key is released.
[2] Column AR means "Autorepeat". If marked "Y", the key has autorepeat enabled.
[3] Column %A indicates the value supplied as the binding value %A. If marked "Y", the same value is supplied as for the unmodified event. If marked "M", a modified value is supplied - a change of case for "Caps Lock" or "Shift" or (Mac only) both, no change if both modifiers are present (Linux, Windows); a numerical value instead of {} for "Num Lock" when a numerical keypad key is pressed, otherwise unmodified; a different character (or none) for "Alt Gr". If marked "-", the value supplied as %A is either the empty string "" or the string "{}". If marked "-*", there are exceptions: a few keys that provide an unmodified value for %A.
[4] The "Right Alt" or "Alt Gr" key is used in combination with certain other keys for composing characters that are not otherwise available on the keyboard. This functionality is provided by the operating system, without use of the Mod5/M5 modifier (Linux) or the Control-Alt modifier (Windows), to generate the value supplied as %A; that value is not necessarily the same for Windows and Linux, or the same as the value produced by the Option key on the Mac.

PC running Windows

A standard PC keyboard on Windows never applies the modifiers

    Meta, M
    Mod4, M4
    Mod5, M5

The PC keyboard's modifier keys on Windows are:

KeyKeyPress %KKeyRelease %KBinding ModifierPE [1]AR [2]%A [3]Notes
ExtendedYIn Windows, this modifier is automatically applied to certain keys of the "Extended" keyboard. See bind(n) for details.
Num LockNum_LockNum_LockCommand, Mod1, or M1YYM
Scroll LockScroll_LockScroll_LockMod3, or M3YYY
Caps LockCaps_LockCaps_LockLockYYM
Shift (Left)Shift_LShift_LShiftYM
Shift (Right)Shift_RShift_LShiftYM
Control (Left)Control_LControl_LControlY-
Control (Right)Control_RControl_LControlY-
"Windows" (Left)Win_LWin_LYNOT a modifier key in Windows.
"Windows" (Right)Win_RWin_RYNOT a modifier key in Windows.
Alt (Left)Alt_LAlt_LAltY-A binding with modifier Alt is overridden by a binding with modifier Option, Mod2, or M2.
Alt Gr [4]Control_L, Alt_RControl_L, Alt_LControl-AltYMA binding with modifier Alt is overridden by a binding with modifier Option, Mod2, or M2. When the modifier key is pressed, two KeyPress events occur: the first with keysym Control_L, the second with keysym Alt_R.

[1], [2], [3], [4] Same as footnotes on Linux table (above).

Mac running MacOS X

A Mac keyboard does not use the modifiers

   Alt
   Extended
   Meta, M
   Mod3, M3
   Mod4, M4
   Mod5, M5

The Mac keyboard's modifier keys on Mac OS X are:

KeyKeyPress %KKeyRelease %KBinding ModifierPE [1]AR [2]%A [3]Notes
Caps LockCaps_LockCaps_LockLockYM
Shift (Left or Right)Shift_LShift_LShiftMThe left and right keys emit the same %K.
Control (Left or Right)Control_LControl_LControl-Control (ctrl) keys.
The left and right keys emit the same %K.
Command (Left or Right)Meta_LMeta_LCommand, Mod1, M1-Command (Apple or ⌘) keys.
The left and right keys emit the same %K.
Alt (Left or Right) [4]Alt_LAlt_LOption, Mod2, M2MOption (Alt or alt) keys.
The left and right keys emit the same %K.

[1], [2], [3] Same as footnotes on Linux table (above).
[4] The "Alt" or "Option" key is used in combination with other keys for composing characters that are not otherwise available on the keyboard. This functionality is provided by the operating system, without use of the Option/Mod2/M2 modifier, to generate the value supplied as %A; that value is not necessarily the same as the value produced by the "Right Alt" or "Alt Gr" key of a PC keyboard on Windows or Linux.

The Binding Modifier "Alt" is not recognised on the Mac, even though some Mac keyboards label the "Option" key "alt".

Using a PC Keyboard on the Mac
The PC keyboard behaves very much like the Mac keyboard described above. The "Windows" modifier key takes the role of the Command/Apple/⌘ key. The Left-Alt and Right-Alt keys are interchangeable, as on a Mac keyboard. The "Num Lock" and "Scroll Lock" keys are not recognised as modifiers: "Num Lock" behaves as "Clear", the Mac key in the same position; pressing or releasing the "Scroll Lock" key does not trigger an event.

Discussion

There are clearly many differences between different platforms. In some cases, there is a reason: e.g.

  • On the Mac, the "Shift" key does not cancel the effect of "Caps Lock" [3]. This makes Tcl/Tk applications behave in the same way as other Mac applications.

Other differences might have a good reason (if so, please add it to the list immediately above). However, some features may exist for historical reasons that are no longer valid. While these features must be retained in the Tcl/Tk 8.x series in order to preserve compatibility, it might be desirable to rationalise the keyboard modifiers in Tcl/Tk 9.0, in order to simplify cross-platform development. See Tk 9.0 WishList.