Skip to content

Latest commit

 

History

History
278 lines (238 loc) · 14.2 KB

KEYS.org

File metadata and controls

278 lines (238 loc) · 14.2 KB

Zutty key mapping sequences

This is a summary of the character sequences Zutty emits in response to various special keys, and how this mapping depends on the state of the terminal.

Mode settings affecting the emitted sequences

ModeDescriptionSetting
DECANMVT52 ModeCSI ? 2 l
DECANMVT100 modeCSI ? 2 h
DECCKM/NCursor Key Mode: Normal/CursorCSI ? 1 l
DECAKM/ACursor Key Mode: ApplicationCSI ? 1 h
DECKPNMNormal/Numeric Keypad ModeESC >
DECKPAMAlternate/Application Keypad ModeESC =

Effect of modifier keys

In case of modifiers being held while a key is pressed, a derived sequence is sent that includes a Modifier Code as an additional (last) parameter of the original sequence. If the original sequence did not start with CSI, the start is changed to CSI (with the exception of keypad keys). If there were no original parameters in the sequence, a first default parameter of 1 is added before appending the Modifier Code.

Modifier codes:

Modifier(s)Code
Shift2
Alt3
Alt + Shift4
Control5
Control + Shift6
Control + Alt7
Control + Alt + Shift8

To make it clearer, in each section we will include some examples of what sequences will result when some modifiers are applied.

Modifiers are generally not applicable to VT52 mode, but are uniform across ANSI and keypad modes.

Sequences that are the same regardless of state

KeySequence
Insert, KP_InsertCSI 2 ~
Delete, KP_DeleteCSI 3 ~
Prior (PageUp), KP_PriorCSI 5 ~
Next (PageDown), KP_NextCSI 6 ~

Modifier examples:

  • Shift + Insert: CSI 2 ; 2 ~
  • Control + PageUp: CSI 5 ; 5 ~

Modifiers work even in VT52 mode.

Function keys

These are independent of cursor key and numeric keypad modes.

KeyVT100VT52
F1, KP_F1SS3 PESC P
F2, KP_F2SS3 QESC Q
F3, KP_F3SS3 RESC R
F4, KP_F4SS3 SESC S
F5CSI 1 5 ~CSI 1 5 ~
F6CSI 1 7 ~CSI 1 7 ~
F7CSI 1 8 ~
F8CSI 1 9 ~
F9CSI 2 0 ~
F10CSI 2 1 ~
F11CSI 2 3 ~
F12CSI 2 4 ~
F13CSI 2 5 ~
F14CSI 2 6 ~
F15CSI 2 8 ~
F16CSI 2 9 ~
F17CSI 3 1 ~
F18CSI 3 2 ~
F19CSI 3 3 ~
F20CSI 3 4 ~

Modifier examples:

  • Shift + F1: CSI 1 ; 2 P
  • Alt + F4: CSI 1 ; 3 S
  • Shift + F5: CSI 1 5 ; 2 ~
  • Control + Shift + F10: CSI 2 1 ; 6 ~

Modifiers are not applied in VT52 mode.

Sequences dependent on cursor key mode setting

KeyVT100 NormalVT100 AppVT52
UpCSI ASS3 AESC A
DownCSI BSS3 BESC B
RightCSI CSS3 CESC C
LeftCSI DSS3 DESC D
HomeCSI HSS3 HESC H
EndCSI FSS3 FESC F

Examples (apply both in Normal and App mode):

  • Alt + Left: CSI 1 ; 3 D
  • Control + Home: CSI 1 ; 5 H

Modifiers are not applied in VT52 mode.

Note that arrow keys on the numeric keypad (KP_Up, etc.) are handled as completely different keys; their encoding method is described in the next section.

Sequences dependent on keypad mode setting

This only affects the keypad. The corresponding non-keypad keys always send the literals in the Normal column. Normal (aka. numeric) mode is shared between VT100 and VT52.

Some keys are received from X with different keysyms based on the NumLock state; for these keys, the second column shows the keysym with NumLock off. In VT100 App mode with NumLock on, all keys generate their literals (as in normal mode), but see further below regarding the Shift key. With NumLock off, mappings are generated as per the below table, depending on the terminal mode setting.

NumLock onNumLock offNormalVT100 AppVT52 App
KP_SpaceSPSS3 SPESC ? SP
KP_TabTABSS3 IESC ? I
KP_EnterCRSS3 MESC ? M
KP_Multiply*SS3 jESC ? j
KP_Add+SS3 kESC ? k
KP_Separator,SS3 lESC ? l
KP_Subtract-SS3 mESC ? m
KP_DecimalKP_Delete.SS3 nESC ? n
KP_Divide/SS3 oESC ? o
KP_0KP_Insert0SS3 pESC ? p
KP_1KP_End1SS3 qESC ? q
KP_2KP_Down2SS3 rESC ? r
KP_3KP_Page_Down3SS3 sESC ? s
KP_4KP_Left4SS3 tESC ? t
KP_5KP_Begin5SS3 uESC ? u
KP_6KP_Right6SS3 vESC ? v
KP_7KP_Home7SS3 wESC ? w
KP_8KP_Up8SS3 xESC ? x
KP_9KP_Page_Up9SS3 yESC ? y
KP_Equal=SS3 XESC ? X

Modifier keys do not cause the SS3 to change to CSI. This is how xterm behaves, and Zutty emulates that behaviour.

Examples:

  • Alt + KP_Minus: SS3 3 m
  • Control + KP_Enter: SS3 5 M
  • Control + KP_Plus: SS3 5 k
  • Control + Shift + KP_Left: SS3 6 t

Modifiers are not applied in VT52 mode.

There is some additional subtlety related to use of the Shift key. Pressing Shift has a momentary effect of inverting the NumLock state. This is not specific to Zutty; it works on the X level and is easily seen via e.g., xev. For example, with NumLock off, hitting “4” on the numeric keypad will generate KP_Left, while hitting the same key with Shift held down will generate KP_4. With NumLock on, results will be reversed: an unmodified keypress will generate KP_4, while a Shift-press will generate KP_Left.

Why is this interesting? Let’s go through the encodings of these keys. In normal (numeric) mode, Zutty generates the literals shown in the Normal column regardless of the NumLock state, and without any modifier encoding. That is, hitting “4” on the keypad will yield a “4” with or without NumLock, and all modifiers will be discarded.

In application (aka. ANSI, aka. alternate) keypad mode, however, all the details come into play. Hitting keypad “4” will generate “4” only if NumLock is on; with NumLock off, it will be encoded as the escape sequence SS3 t. Further, holding Shift while hitting the same key will have slightly asymmetrical results depending on NumLock state:

  • With NumLock off, Zutty will consider the keypress as a modifier combination of Shift plus KP_Left, and encode it as SS3 2 t. In the same manner, Control plus KP_Left will be encoded as SS3 5 t, and so on for other (possibly compounded) modifiers and keys.
  • With NumLock on, the baseline is to generate literals only, just as in numeric mode. Modifiers will be ignored, so Control + KP_4 (the keysym Zutty sees due to NumLock being on) will still generate a “4” only. However, if Shift is among the active modifiers, it will turn KP_4 back into KP_Left, and the result will be, again, encoded as SS3 2 t (or the corresponding modifier code).

The intention is that Zutty behaves just like xterm with VT220-style function keys. In case of manual side-by-side comparisons, please remember to put xterm into “VT220 Keyboard” mode (by choosing it in the Control + left-click menu, setting the XTerm.keyboardType X resource to vt220, or passing -kt vt220 on the command line).

Special key combinations

The resource settings altSendsEscape and modifyOtherKeys (modeled after xterm) control how other key combinations (not specified in the above tables) are encoded.

The encoding rules are, by and large, meant to be the same as that of xterm; please refer to its extensive documentation for details. As a complement, below we present several example key encodings for different values of modifyOtherKeys (columns 0, 1 and 2), with an altSendsEscape setting of true (the default).

Key012
Shift-aAACSI 27 ; 2 ; 65 ~
Shift-SpaceSpaceSpaceCSI 27 ; 2 ; 32 ~
Shift-TABCSI ZCSI ZCSI 27 ; 2 ; 9 ~
Shift-ReturnReturnCSI 27 ; 2 ; 13 ~CSI 27 ; 2 ; 13 ~
Control-Space^@^@CSI 27 ; 5 ; 32 ~
Control-Alt-SpaceESC ^@ESC ^@CSI 27 ; 7 ; 32 ~
Control-Shift-Space^@^@CSI 27 ; 6 ; 32 ~
Control-Alt-Shift-SpaceESC ^@ESC ^@CSI 27 ; 8 ; 32 ~
Control-TABTABCSI 27 ; 5 ; 9 ~CSI 27 ; 5 ; 9 ~
Control-ReturnReturnCSI 27 ; 5 ; 13 ~CSI 27 ; 5 ; 13 ~
Control-Alt-ReturnESC ReturnCSI 27 ; 7 ; 13 ~CSI 27 ; 7 ; 13 ~
Control-Alt-Shift-ReturnESC ReturnCSI 27 ; 8 ; 13 ~CSI 27 ; 8 ; 13 ~
Control-/^_^_CSI 27 ; 5 ; 47 ~
Control-00CSI 27 ; 5 ; 48 ~CSI 27 ; 5 ; 48 ~
Control-11CSI 27 ; 5 ; 49 ~CSI 27 ; 5 ; 49 ~
Control-2^@^@CSI 27 ; 5 ; 50 ~
Control-3ESCESCCSI 27 ; 5 ; 51 ~
Control-4^\^\CSI 27 ; 5 ; 52 ~
Control-5^]^]CSI 27 ; 5 ; 53 ~
Control-6^^^^CSI 27 ; 5 ; 54 ~
Control-7^_^_CSI 27 ; 5 ; 55 ~
Control-8DELDELCSI 27 ; 5 ; 56 ~
Control-99CSI 27 ; 5 ; 57 ~CSI 27 ; 5 ; 57 ~
Control-! (Control-Shift-1)!CSI 27 ; 6 ; 33 ~CSI 27 ; 6 ; 33 ~
Control-@ (Control-Shift-2)^@^@CSI 27 ; 6 ; 64 ~
Control-# (Control-Shift-3)#CSI 27 ; 6 ; 35 ~CSI 27 ; 6 ; 35 ~
Control-$ (Control-Shift-4)$CSI 27 ; 6 ; 36 ~CSI 27 ; 6 ; 36 ~
Control-% (Control-Shift-5)%CSI 27 ; 6 ; 37 ~CSI 27 ; 6 ; 37 ~
Control-^ (Control-Shift-6)^^^^CSI 27 ; 6 ; 94 ~
Control-& (Control-Shift-7)&CSI 27 ; 6 ; 38 ~CSI 27 ; 6 ; 38 ~
Control-* (Control-Shift-8)*CSI 27 ; 6 ; 42 ~CSI 27 ; 6 ; 42 ~
Control-( (Control-Shift-9)(CSI 27 ; 6 ; 40 ~CSI 27 ; 6 ; 40 ~
Control-) (Control-Shift-0))CSI 27 ; 6 ; 41 ~CSI 27 ; 6 ; 41 ~
Control-[^[^[CSI 27 ; 5 ; 91 ~
Control-]^]^]CSI 27 ; 5 ; 93 ~
Control-{ (Control-Shift-[)^[^[CSI 27 ; 6 ; 123 ~
Control-} (Control-Shift-])^]^]CSI 27 ; 6 ; 125 ~
Control-c^C^CCSI 27 ; 5 ; 99 ~
Control-d^D^DCSI 27 ; 5 ; 100 ~
Control-iTABTABCSI 27 ; 5 ; 105 ~
Control-Shift-ITABTABCSI 27 ; 6 ; 73 ~
Control-x^X^XCSI 27 ; 5 ; 120 ~
Control-Alt-xESC ^XESC ^XCSI 27 ; 7 ; 120 ~
Control-Shift-D^D^DCSI 27 ; 6 ; 68 ~
Control-Alt-Shift-DESC ESCESC ESCCSI 27 ; 8 ; 68 ~
Control-;;CSI 27 ; 5 ; 59 ~CSI 27 ; 5 ; 59 ~
Control-: (Control-Shift-;):CSI 27 ; 6 ; 58 ~CSI 27 ; 6 ; 58 ~
Control-\^\^\CSI 27 ; 5 ; 92 ~
Control-¦ (Control-Shift-\)^\^\CSI 27 ; 6 ; 124 ~
Control-`^@^@CSI 27 ; 5 ; 96 ~
Control-~ (Control-Shift-`)^^^^CSI 27 ; 6 ; 126 ~
Alt-SpaceESC SpaceESC SpaceCSI 27 ; 3 ; 32 ~
Alt-Shift-SpaceESC SpaceESC SpaceCSI 27 ; 4 ; 32 ~
Alt-TABESC TABESC TABCSI 27 ; 3 ; 9 ~
Alt-ReturnESC ReturnCSI 27 ; 3 ; 13 ~CSI 27 ; 3 ; 13 ~
Alt-Shift-ReturnESC ReturnCSI 27 ; 4 ; 13 ~CSI 27 ; 4 ; 13 ~
Alt-dESC dESC dCSI 27 ; 3 ; 100 ~
Alt-Shift-dESC DESC DCSI 27 ; 4 ; 68 ~
Alt-xESC xESC xCSI 27 ; 3 ; 120 ~
Alt-Shift-XESC XESC XCSI 27 ; 4 ; 88 ~