Are there any linux terminals which can handle all key combinations?
When you press a key or key combination in a terminal, it is transmitted to the application running in the terminal as a sequence of one or more characters. For example, when you press a, the application receives a
. When you press Enter, the application receives the character CR
(a.k.a. ^M
(pronounced “control-emm”), a.k.a. character number 13, a.k.a. \r
or \015
). Key combinations involving Alt are typically transmitted as the character ESC
(a.ka. ^[
a.k.a. \e
or \033
) followed by the sequence for the key or key combination without Alt. Function keys and other key combinations are transmitted as escape sequences beginning with \e[
or \eO
.
The escapes sequences are not fully standardized, and terminals typically ignore certain attributes for certain keys. For example, Ctrl+Shift+letter is often transmitted exactly like Ctrl+letter by default.
You can see what your terminal sends for a key combination by pressing Ctrl+V followed by that key combination in a shell prompt, or C-q
or C-h c
followed by the key combination in Emacs.
With some terminal emulators, you can configure the escape sequences for each key. On Xterm, this is done through X resources. Most setups read resources from ~/.Xresources
when X starts, and you can load the file manually with xrdb -merge ~/.Xresources
.
Term.VT100.translations: #override \n\
Ctrl ~Shift ~Meta <key>Return: string("\033[73;5~") \n\
Ctrl Shift ~Meta <key>percent: string("\033[37;6~")
A common convention uses escape sequences of the form ESC [ number1 ; number2 ~
for function keys with modifiers. number1
indicates the function key (15
to 24
for F5 to F12 — for historical reasons, F1 through F4 have different escape sequences) and number2
indicates the modifier (2
for Shift, 3
for Meta, 5
for Ctrl, 7
for Ctrl+Meta, and add 1 for Shift with at least one of Ctrl or Meta).
Emacs translates escape sequences into its internal key representation through input-decode-map
or local-function-key-map
(or function-key-map
before Emacs 23).
(define-key local-function-key-map "\033[73;5~" [(control return)])
(define-key local-function-key-map "\033[37;6~" [(control ?L)])