Skip to content

Chapter 5. Keyboards

A KEYCODE represents a physical (or logical) key. Keycodes lie in the inclusive range [8,255]. A keycode value carries no intrinsic information, although server implementors may attempt to encode geometry information (for example, matrix) to be interpreted in a server-dependent fashion. The mapping between keys and keycodes cannot be changed using the protocol.

A KEYSYM is an encoding of a symbol on the cap of a key. The set of defined KEYSYMs include the character sets Latin-1, Latin-2, Latin-3, Latin-4, Kana, Arabic, Cyrillic, Greek, Tech, Special, Publish, APL, Hebrew, Thai, and Korean as well as a set of symbols common on keyboards (Return, Help, Tab, and so on). KEYSYMs with the most significant bit (of the 29 bits) set are reserved as vendor-specific.

A list of KEYSYMs is associated with each KEYCODE. The list is intended to convey the set of symbols on the corresponding key. If the list (ignoring trailing NoSymbol entries) is a single KEYSYM "K", then the list is treated as if it were the list "K NoSymbol K NoSymbol". If the list (ignoring trailing NoSymbol entries) is a pair of KEYSYMs "K1 K2", then the list is treated as if it were the list "K1 K2 K1 K2". If the list (ignoring trailing NoSymbol entries) is a triple of KEYSYMs "K1 K2 K3", then the list is treated as if it were the list " K1 K2 K3 NoSymbol". When an explicit "void" element is desired in the list, the value VoidSymbol can be used.

The first four elements of the list are split into two groups of KEYSYMs. Group 1 contains the first and second KEYSYMs, Group 2 contains the third and fourth KEYSYMs. Within each group, if the second element of the group is NoSymbol, then the group should be treated as if the second element were the same as the first element, except when the first element is an alphabetic KEYSYM "K" for which both lowercase and uppercase forms are defined. In that case, the group should be treated as if the first element were the lowercase form of "K" and the second element were the uppercase form of "K".

The standard rules for obtaining a KEYSYM from a KeyPress event make use of only the Group 1 and Group 2 KEYSYMs; no interpretation of other KEYSYMs in the list is defined. The modifier state determines which group to use. Switching between groups is controlled by the KEYSYM named MODE SWITCH, by attaching that KEYSYM to some KEYCODE and attaching that KEYCODE to any one of the modifiers Mod1 through Mod5. This modifier is called the "group modifier". For any KEYCODE, Group 1 is used when the group modifier is off, and Group 2 is used when the group modifier is on.

The Lock modifier is interpreted as CapsLock when the KEYSYM named CAPS LOCK is attached to some KEYCODE and that KEYCODE is attached to the Lock modifier. The Lock modifier is interpreted as ShiftLock when the KEYSYM named SHIFT LOCK is attached to some KEYCODE and that KEYCODE is attached to the Lock modifier. If the Lock modifier could be interpreted as both CapsLock and ShiftLock, the CapsLock interpretation is used.

The operation of "keypad" keys is controlled by the KEYSYM named NUM LOCK, by attaching that KEYSYM to some KEYCODE and attaching that KEYCODE to any one of the modifiers Mod1 through Mod5. This modifier is called the "numlock modifier". The standard KEYSYMs with the prefix KEYPAD in their name are called "keypad" KEYSYMs; these are KEYSYMS with numeric value in the hexadecimal range #xFF80 to #xFFBD inclusive. In addition, vendor-specific KEYSYMS in the hexadecimal range #x11000000 to #x1100FFFF are also keypad KEYSYMs.

Within a group, the choice of KEYSYM is determined by applying the first rule that is satisfied from the following list:

  • The numlock modifier is on and the second KEYSYM is a keypad KEYSYM. In this case, if the Shift modifier is on, or if the Lock modifier is on and is interpreted as ShiftLock, then the first KEYSYM is used; otherwise, the second KEYSYM is used.

  • The Shift and Lock modifiers are both off. In this case, the first KEYSYM is used.

  • The Shift modifier is off, and the Lock modifier is on and is interpreted as CapsLock. In this case, the first KEYSYM is used, but if that KEYSYM is lowercase alphabetic, then the corresponding uppercase KEYSYM is used instead.

  • The Shift modifier is on, and the Lock modifier is on and is interpreted as CapsLock. In this case, the second KEYSYM is used, but if that KEYSYM is lowercase alphabetic, then the corresponding uppercase KEYSYM is used instead.

  • The Shift modifier is on, or the Lock modifier is on and is interpreted as ShiftLock, or both. In this case, the second KEYSYM is used.

The mapping between KEYCODEs and KEYSYMs is not used directly by the server; it is merely stored for reading and writing by clients.