Keyboard and Mouse
Every key of Hanshi and of its terminal, every use of the mouse, and what a program in the terminal receives when you press a key: the keyboards Hanshi can imitate, Alt and the other modifiers, and the keyboard protocols programs can ask for.
1. Hanshi's keys
These keys work in every terminal of the window. Hanshi takes them before the program sees them.
| Key | What it does |
|---|---|
Ctrl+Shift+P |
Preferences. |
Ctrl+Shift+T |
A new tab. |
Ctrl+Shift+W |
Closes the tab (with a question when a program runs in it). |
Ctrl+Page Up, Ctrl+Page Down |
The tab before, the tab after. |
With tabs switched off in Preferences, the last three go to the program. While the window has only one terminal, Ctrl+Shift+W closes the window (with the same question), and Ctrl+Page Up and Ctrl+Page Down go to the program. A key held together with Alt is never one of these.
2. The terminal's keys
| Key | What it does |
|---|---|
Ctrl+Shift+C |
Copies the selection to the clipboard. |
Ctrl+Shift+V |
Pastes the clipboard. |
Shift+Insert |
Pastes the PRIMARY selection. |
Ctrl+Shift+F |
Opens or closes the search bar. |
Ctrl+Shift+Space |
Selection with the keyboard. |
Ctrl+Shift+O |
A letter on each link in view, to open one with a key. |
Ctrl+Shift+Up, Ctrl+Shift+Down |
From prompt to prompt (shell integration). |
Shift+Page Up, Shift+Page Down |
Scroll by a screen. |
Ctrl+Plus or Ctrl+=, Ctrl+Minus, Ctrl+0 |
Font size: larger, smaller, as the settings say. Not while a program uses modifyOtherKeys. |
Ctrl+Break |
Sends the answerback message of Preferences > Programs, as the Break key of a VT100 did. |
A key held with Alt always goes to the program. Every other key goes to the program too: Ctrl+C, Ctrl+V, Ctrl+Minus and the rest keep their usual meaning in the shell and in editors.
Keys of the bars
| While | Keys |
|---|---|
| The search bar is open | Typing adds to the text; Backspace, Enter (older match), Shift+Enter (newer match), Alt+C (case), Alt+R (pattern), Escape (close). Keys with Ctrl go to the program (Using the Terminal). |
| The keyboard selection runs | Arrows or h j k l, w, b, 0, $, Home, End, g, G, Page Up, Page Down, v, V, y or Enter (copy), Escape or q. |
| Links have letters | a to z and A to Z open a link; any other key ends. |
| A paste waits | Enter pastes, Escape drops it; other keys do nothing. |
| The question before closing | Enter is Cancel, Escape is Cancel. |
| Preferences | Escape is Cancel. |
3. The mouse
| Mouse | What it does |
|---|---|
| Drag | Selects characters. Two clicks select words, three select lines. |
| Ctrl and drag | Selects a rectangle of cells. |
| Ctrl and click | Opens the link under the pointer, when the button goes up with no drag. |
| Ctrl and the pointer on a link | Underlines the link. |
| Click in the margin | On a prompt's mark: selects that command's output; two clicks hide or show it. A third quick click does nothing, so a triple-click hides the output and leaves it hidden. |
| Middle button | Pastes the PRIMARY selection. |
| Right button | The terminal's menu (The Window and Tabs). |
| Wheel | Scrolls through the scrollback, three lines a step. In a full-screen program that asked for it, it sends Up and Down. |
| Click on a tab, drag a tab, the x of a tab | Shows that terminal, moves the tab, closes the tab. |
| Wheel over the tabs | Scrolls the tabs, when they do not all fit. |
When a program uses the mouse (vim with set mouse=a, htop, mc, tmux), the clicks, the wheel and, if it asks, the movements of the mouse go to the program. Hold Shift to use the mouse for the terminal instead: to select, paste, scroll or open the menu.
4. What a program receives
The terminal sends a program the keys the way xterm does, with TERM=xterm-256color, so programs know them without any setup. The modifiers count as in xterm: a key with Shift, Alt or Control sends its sequence with a number for the modifiers (2 Shift, 3 Alt, 5 Control, and their sums plus 1), for example CSI 1;5A for Control+Up.
| Key | What it sends |
|---|---|
| Arrows, Home, End | CSI A to CSI D, CSI H, CSI F; with the cursor keys in application mode (which a full-screen program sets), SS3 A and so on. |
| Insert, Delete, Page Up, Page Down | CSI 2~, CSI 3~, CSI 5~, CSI 6~. |
| F1 to F4 | SS3 P to SS3 S, the PF keys of the VT100. |
| F5 to F12 | CSI 15~ to CSI 24~, as xterm. |
| F13 to F20 | As xterm sends them on a PC: F1 to F8 with Shift, CSI 1;2P to CSI 1;2S and CSI 15;2~ to CSI 19;2~. With the VT220 keyboard, the VT220's own CSI 25~ to CSI 34~. |
| Shift+F1 to Shift+F20 | What a program defined for them with DEC's user-defined keys (DECUDK), when it did. |
| Backspace | DEL (127); Control+Backspace sends BS (8). A program can swap the two (DECBKM). |
| Tab, Shift+Tab | TAB, and CSI Z. |
| Return | CR, or CR LF when the program set the new-line mode. |
| Escape | ESC; Alt+Escape sends ESC twice. |
| Ctrl and a key | The control code: Ctrl+A to Ctrl+Z, Ctrl+Space and Ctrl+2 (NUL), Ctrl+3 (ESC), Ctrl+4 to Ctrl+6, Ctrl+7 and Ctrl+/ (US), Ctrl+8 and Ctrl+? (DEL). |
| Alt and a key | ESC in front of the key's character, as xterm's metaSendsEscape. A program can ask for the character with its eighth bit set instead (modes 1036 and 1034). |
| The keypad | Its digits and signs, as a PC's; in application keypad mode with the VT220 keyboard, the VT220's own codes. Its Enter sends CR, and SS3 M in application keypad mode with any keyboard. |
The pseudoterminal is set up for UTF-8 (IUTF8), so Backspace in the shell's line editing removes a whole character.
The keyboard choice
Preferences > Programs > Keyboard chooses which keyboard the function keys and the editing keys imitate. It only changes keys pressed without a modifier. With PC and VT220, programs get TERM=xterm-256color. With Sun, HP, SCO, rxvt and Linux console, a terminal that starts after the choice gives its programs the TERM of that keyboard (the last column below; for rxvt, rxvt-256color when it is installed), so that programs know its keys. When that terminfo entry is not installed, TERM stays xterm-256color.
| Choice | What changes | Taken from |
|---|---|---|
| PC | Nothing: the keys as above. Programs expect this. | xterm's default |
| VT220 | Home and End are the VT220's Find and Select (CSI 1~, CSI 4~); in application keypad mode the keypad sends SS3 p to SS3 y for its digits, and its plus is the VT220's comma. A program can switch this on itself (mode 1061). |
xterm's VT220 keyboard, the VT220 manual |
| Sun | F1 to F12 and the editing keys send Sun's codes (CSI 224z and so on). Also mode 1051. |
terminfo xterm-sun |
| HP | F1 to F8, the arrows and the editing keys send HP's codes (ESC p and so on). Also mode 1052. |
terminfo xterm-hp |
| SCO | F1 to F12, the arrows and the editing keys send SCO's codes (CSI M and so on). Also mode 1053. |
terminfo xterm-sco |
| rxvt | F1 to F5 send CSI 11~ to CSI 15~, Home and End CSI 7~ and CSI 8~. |
terminfo rxvt |
| Linux console | F1 to F5 send CSI [A to CSI [E, Home and End CSI 1~ and CSI 4~. |
terminfo linux |
Keyboard modes a program can ask for
- modifyOtherKeys (xterm), levels 1 and 2: keys such as Control+Return, Control+Tab or, at level 2, Control or Alt with any character are sent as
CSI 27;modifiers;code~, or asCSI code;modifiers uwhen the program asks for that form. While it is on, the font size keys go to the program. - The kitty keyboard protocol: a program that asks for it (
CSI > flags u) gets Escape and keys with Alt, Control or Super as unambiguous codes and, by the flags it sets, key repeats and key releases, the key with Shift and the key of the US layout, every key including the modifier keys themselves, and the text a key types. Num Lock and Caps Lock are reported too. - Mouse reports in all of xterm's forms (Terminal Features), focus reports when the terminal gets or loses the keyboard, and bracketed paste.
5. Known limitations
- Hanshi's keys and the terminal's keys cannot be changed.
- With the kitty keyboard protocol on, the arrows, Home and End are always sent in their
CSIform, also when the program set application cursor keys.