# TinyEdit key codes

This is how each key reaches the editor. A key does what KEYS.md says it
does; this manual says what the key is on a terminal, in the Windows
console and in a web browser, and which keys a terminal cannot send.

Every row of the table is tested: the bytes are given to the terminal
decoder, the console codes to the console reader, and the browser keys to the
page's key reader, and each must give the key the row names.

## Terminals

TinyEdit reads the bytes an xterm-like terminal sends (xterm, iTerm2, Terminal,
tmux, the Windows Terminal over ssh, and the like). It reads both forms of the
cursor keys (`ESC [ A` and `ESC O A`) and the terminfo entry's own key
strings.

- **Modifiers** are xterm's: a key with Shift, Alt or Ctrl is `ESC [ 1 ; m X`
  (or `ESC [ n ; m ~`), where m is 1, plus 1 for Shift, plus 2 for Alt,
  plus 4 for Ctrl. Shift+Ctrl+Left is `ESC [ 1 ; 6 D`.
- **Control letters** are the bytes 01h to 1Ah. Ctrl+H (08h) is Backspace,
  Ctrl+I (09h) is Tab, and Ctrl+M (0Dh) is Enter on a terminal: they cannot be
  told apart. In the modern keys, Replace is Ctrl+H or Ctrl+R for this reason.
- **Alt** and a key is Esc and the key at once. A terminal sends no Alt alone,
  so TinyEdit takes Esc alone (nothing more within 25 ms) or F10 for the menu
  bar. A Mac's Terminal and iTerm2 send a character for Option+letter, "ƒ" for
  Option+F; TinyEdit reads it as Alt+F where F is a hotkey on the screen.
  Setting the terminal to send Esc+ for Option makes it exact.
- **Not sent by a terminal:** Ctrl+Enter, Ctrl+Shift+letter, and Alt alone.
  The table gives the key to use instead.
- **The mouse** is xterm's SGR reports (`ESC [ < b ; x ; y M` for a press or a
  move, `m` for a release; b is 0 for the left button, 32 added for a move, 64
  and 65 for the wheel; Shift adds 4, Alt 8, Ctrl 16). TinyEdit turns them on
  at the start and off at the end, on terminals that take a cursor shape.

## The Windows console

TinyEdit reads key records, so it gets every key apart: Ctrl+H is not
Backspace, Ctrl+Enter is not Enter, and Alt pressed and let go alone is a key
(it opens the menu bar). AltGr (Right Alt with Left Ctrl) gives the character,
as it does elsewhere. The table gives the virtual-key code in hexadecimal.

## A web browser

The page gives the editor the browser's key events: `key` and `code`, with
Shift, Ctrl and Alt. It stops the browser using the keys TinyEdit takes
(Alt, F1, Tab, Ctrl+S and the rest). F5, F11, F12 and every key with Cmd or the
Windows key stay the browser's. A browser keeps Ctrl+N, Ctrl+T and Ctrl+W for
itself where a page cannot stop it. Alt and a letter is read by the key's place
(`code`), so a Mac's Option+F is Alt+F.

## The table

Terminal: the bytes. Console: the virtual-key code. Web: `KeyboardEvent.key`.
A dash means none: see the note.

| Key | Terminal | Console | Web | Note |
|---|---|---|---|---|
| Up | `ESC [ A` | 26 | ArrowUp |  |
| Shift+Up | `ESC [ 1 ; 2 A` | 26 | ArrowUp |  |
| Ctrl+Up | `ESC [ 1 ; 5 A` | 26 | ArrowUp |  |
| Shift+Ctrl+Up | `ESC [ 1 ; 6 A` | 26 | ArrowUp |  |
| Down | `ESC [ B` | 28 | ArrowDown |  |
| Shift+Down | `ESC [ 1 ; 2 B` | 28 | ArrowDown |  |
| Ctrl+Down | `ESC [ 1 ; 5 B` | 28 | ArrowDown |  |
| Shift+Ctrl+Down | `ESC [ 1 ; 6 B` | 28 | ArrowDown |  |
| Right | `ESC [ C` | 27 | ArrowRight |  |
| Shift+Right | `ESC [ 1 ; 2 C` | 27 | ArrowRight |  |
| Ctrl+Right | `ESC [ 1 ; 5 C` | 27 | ArrowRight |  |
| Shift+Ctrl+Right | `ESC [ 1 ; 6 C` | 27 | ArrowRight |  |
| Left | `ESC [ D` | 25 | ArrowLeft |  |
| Shift+Left | `ESC [ 1 ; 2 D` | 25 | ArrowLeft |  |
| Ctrl+Left | `ESC [ 1 ; 5 D` | 25 | ArrowLeft |  |
| Shift+Ctrl+Left | `ESC [ 1 ; 6 D` | 25 | ArrowLeft |  |
| Home | `ESC [ H` | 24 | Home |  |
| Shift+Home | `ESC [ 1 ; 2 H` | 24 | Home |  |
| Ctrl+Home | `ESC [ 1 ; 5 H` | 24 | Home |  |
| Shift+Ctrl+Home | `ESC [ 1 ; 6 H` | 24 | Home |  |
| End | `ESC [ F` | 23 | End |  |
| Shift+End | `ESC [ 1 ; 2 F` | 23 | End |  |
| Ctrl+End | `ESC [ 1 ; 5 F` | 23 | End |  |
| Shift+Ctrl+End | `ESC [ 1 ; 6 F` | 23 | End |  |
| PgUp | `ESC [ 5 ~` | 21 | PageUp |  |
| Shift+PgUp | `ESC [ 5 ; 2 ~` | 21 | PageUp |  |
| Ctrl+PgUp | `ESC [ 5 ; 5 ~` | 21 | PageUp |  |
| Shift+Ctrl+PgUp | `ESC [ 5 ; 6 ~` | 21 | PageUp |  |
| PgDn | `ESC [ 6 ~` | 22 | PageDown |  |
| Shift+PgDn | `ESC [ 6 ; 2 ~` | 22 | PageDown |  |
| Ctrl+PgDn | `ESC [ 6 ; 5 ~` | 22 | PageDown |  |
| Shift+Ctrl+PgDn | `ESC [ 6 ; 6 ~` | 22 | PageDown |  |
| Ins | `ESC [ 2 ~` | 2D | Insert |  |
| Shift+Ins | `ESC [ 2 ; 2 ~` | 2D | Insert |  |
| Ctrl+Ins | `ESC [ 2 ; 5 ~` | 2D | Insert |  |
| Shift+Ctrl+Ins | `ESC [ 2 ; 6 ~` | 2D | Insert |  |
| Del | `ESC [ 3 ~` | 2E | Delete |  |
| Shift+Del | `ESC [ 3 ; 2 ~` | 2E | Delete |  |
| Ctrl+Del | `ESC [ 3 ; 5 ~` | 2E | Delete |  |
| Shift+Ctrl+Del | `ESC [ 3 ; 6 ~` | 2E | Delete |  |
| Enter | `CR` | 0D | Enter |  |
| Ctrl+Enter | - | 0D | Enter | A terminal sends Enter. Ctrl+J does the same. |
| Tab | `TAB` | 09 | Tab |  |
| Shift+Tab | `ESC [ Z` | 09 | Tab |  |
| Backspace | `DEL` | 08 | Backspace | Some terminals send Ctrl+H (08h) for it; TinyEdit takes both. |
| Alt+Backspace | `ESC DEL` | 08 | Backspace | Undo. |
| Esc | `ESC` | 1B | Escape | Alone: the menu bar. A terminal sends Esc alone when no more bytes come in 25 ms. |
| F1 | `ESC O P` | 70 | F1 |  |
| F3 | `ESC O R` | 72 | F3 |  |
| Shift+F3 | `ESC [ 1 ; 2 R` | 72 | F3 |  |
| F10 | `ESC [ 2 1 ~` | 79 | F10 | The menu bar, as Esc. |
| Alt+F1 | `ESC [ 1 ; 3 P` | 70 | F1 | Back, in Help. |
| Ctrl+A | `^A` | 41 | a |  |
| Ctrl+B | `^B` | 42 | b |  |
| Ctrl+C | `^C` | 43 | c |  |
| Ctrl+D | `^D` | 44 | d |  |
| Ctrl+E | `^E` | 45 | e |  |
| Ctrl+F | `^F` | 46 | f |  |
| Ctrl+G | `^G` | 47 | g |  |
| Ctrl+H | - | 48 | h | A terminal sends Backspace. Use Ctrl+R for Replace. |
| Ctrl+I | - | 49 | i | A terminal sends Tab. |
| Ctrl+J | `^J` | 4A | j |  |
| Ctrl+K | `^K` | 4B | k |  |
| Ctrl+L | `^L` | 4C | l |  |
| Ctrl+M | - | 4D | m | A terminal sends Enter. |
| Ctrl+N | `^N` | 4E | n |  |
| Ctrl+O | `^O` | 4F | o |  |
| Ctrl+P | `^P` | 50 | p |  |
| Ctrl+Q | `^Q` | 51 | q | A serial console (9front's, in QEMU) keeps it as XON and sends nothing: use Ctrl+K,Q. vt(1) in a rio window sends it. |
| Ctrl+R | `^R` | 52 | r |  |
| Ctrl+S | `^S` | 53 | s | A serial console (9front's, in QEMU) keeps it as XOFF and sends nothing: use Ctrl+K,D. vt(1) in a rio window sends it. |
| Ctrl+T | `^T` | 54 | t |  |
| Ctrl+U | `^U` | 55 | u |  |
| Ctrl+V | `^V` | 56 | - | In a browser Ctrl+V (and Cmd+V) is the browser's paste: the page pastes its text as Shift+Ins does, with no permission asked. |
| Ctrl+W | `^W` | 57 | w |  |
| Ctrl+X | `^X` | 58 | x |  |
| Ctrl+Y | `^Y` | 59 | y |  |
| Ctrl+Z | `^Z` | 5A | z |  |
| Ctrl+Shift+S | - | 53 | S | A terminal sends Ctrl+S. Use Ctrl+K,S for Save As. |
| Ctrl+Shift+Z | - | 5A | Z | A terminal sends Ctrl+Z. Use Ctrl+Y for Redo. |
| Alt+F | `ESC f` | 46 | f | Esc and the letter at once. A Mac's Option+F is "ƒ"; TinyEdit takes it as Alt+F where F is a hotkey. |
| Alt+X | `ESC x` | 58 | x | Exit, in the modern keys. |
| Alt+0 | `ESC 0` | 30 | 0 | Go to bookmark 0, in the modern keys; also Alt+1 to Alt+3. |
| Alt | - | - | Alt | Alt pressed and let go with no key between: the menu bar. A terminal cannot send it: use Esc or F10. |
