What the keyboard sends in a VT session
The exact bytes the app sends for Esc, Backspace, Delete, Home, End, arrows with Ctrl or Alt, Shift+Tab, function keys and Ctrl chords in an SSH, Mosh or Telnet VT session, and how to see what a key sends.
In a VT session, every key goes to the host as bytes, except a few app shortcuts. This page lists what each key sends. Which of them a program understands depends on the program and on the terminal type the host thinks you have: see Keys and key codes and TERM and terminfo.
Esc without an Esc key
A keyboard with no Esc key can still send it:
Ctrl+[sends Escape. So does Ctrl+3.- On the utility key bar, tap Esc. See Utility key bar and on-screen keyboard.
Key table
ESC is the byte 0x1B. A modifier number is added to cursor and editing keys: 2 is Shift, 3 is Alt, 4 is Shift+Alt, 5 is Ctrl, 6 is Ctrl+Shift, 7 is Ctrl+Alt and 8 is all three.
- Esc:
ESC. With Alt,ESC ESC. - Backspace: 0x7F (DEL). With Ctrl, 0x08 (
^H). With Alt,ESCthen 0x7F. - Delete:
ESC [ 3 ~ - Tab: the Tab character. With Shift,
ESC [ Z. - Return: carriage return. In the host's new-line mode, carriage return and line feed.
- Up, Down, Right, Left:
ESC [ A,B,C,D. When the host has turned on application cursor mode,ESC O Aand so on. With a modifier,ESC [ 1 ; n Aand so on, so Ctrl+Right isESC [ 1 ; 5 C. Shift with an arrow on its own selects text instead, and sends nothing. - Home, End:
ESC [ 1 ~andESC [ 4 ~. With a modifier,ESC [ 1 ; n HandESC [ 1 ; n F. - Insert, Page Up, Page Down:
ESC [ 2 ~,ESC [ 5 ~,ESC [ 6 ~ - F1 to F4:
ESC O P,Q,R,S - F5 to F12:
ESC [ 15 ~,17,18,19,20,21,23,24followed by~ - Ctrl and a letter: the control character: Ctrl+A is 0x01 up to Ctrl+Z, 0x1A. Ctrl+V pastes instead, and Ctrl+C copies when text is selected.
- Alt and a character:
ESCfollowed by the character
The other Ctrl chords are Ctrl+Space, Ctrl+2 or Ctrl+@ (0x00), Ctrl+\ or Ctrl+4 (0x1C), Ctrl+] or Ctrl+5 (0x1D), Ctrl+6 or Ctrl+^ (0x1E), Ctrl+- or Ctrl+_ or Ctrl+/ or Ctrl+7 (0x1F), and Ctrl+8 or Ctrl+? (0x7F). To check that Ctrl+Space reaches a program on the host, see Ctrl+Space not working over SSH or in tmux: the NUL byte and how to test it.
A few app shortcuts such as Ctrl+, are also not sent: see VT220 and VT.
See what a key sends
On the host, run:
cat -v
Press a key and cat prints it with the escape character written as ^[. Pressing Home prints ^[[1~, and Ctrl+Right prints ^[[1;5C. Press Ctrl+D to end cat.
If a key does nothing
The app sends the bytes above. Whether a program acts on them depends on the host. A program that expects a different sequence for Home or End, or does not map Ctrl+Arrow or Ctrl+Backspace to word movement or deletion, ignores them or prints them. The fix is on the host, in the program's key bindings or the terminal type it uses.