Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: key codes table.

So, using a tweaked zkbd I came up with this, I think it's pretty near all of them:

BEGINNER'S GUIDE TO ZSH KEYBOARD ASSIGNMENTS, AKA 'KEYBOARD BINDINGS'. (comments, improvements, bitter denunciations welcome: rayandrews at eastlink dot ca)

'Available' key combinations on a '101' PC keyboard attached to a PC running 'zsh' under xfce4 under Debian Linux (I don't know who's 'in charge'). All combinations that produce duplicate codes within the 'grey' keys have been removed except for the simplest avatar which is shown. Note, some grey keys/combinations have '^letter' duplicates, like 'Enter' == '^M', these have not been removed. Other active combinations were not 'available' since used by the system, even from console, eg. 'Alt+Function' keys switch terminals. Perhaps the 'Meta' key would do more, but this is with a 101 KB. Interesting that there are far more combinations available in DOS, such as Ctrl+Function -- all available in DOS, none of them available in Linux, so it seems. None of the triple key combinations (eg. 'Ctrl+Alt+Up') produced any unique codes within the grey keys, but they do produce codes in the white keys. Interesting anomalies: '^[[22' '^[[27' '^[[30' are 'missing', you hafta wonder why those numbers were skipped. (Which is to say that you might expect 'F11' to be '^[[22' not '^[[23'.)

The key codes shown are as they would be output by 'showkeys -a' or 'bindkey' at CLI. However, for some reason if you use 'bindkey' within a script (as in '.zshrc') ' ^[ ' must be replaced with ' \e ', thus at CLI:

  bindkey -s '^[[[A' 'my-command \C-m'

... bind 'F1' to 'my-command' and execute it (the ' \C-m ' simulates the 'Enter' key).

in '.zshrc':

  bindkey -s '\e[25' 'my-command1 ; my command2 \C-m'

... bind 'Shift-F1' to 'my-command1' followed by 'my-command2' and execute both of them.


key[F1]        = '^[[[A'
key[F2]        = '^[[[B'
key[F3]        = '^[[[C'
key[F4]        = '^[[[D'
key[F5]        = '^[[[E'
key[F6]        = '^[[17~'
key[F7]        = '^[[18~'
key[F8]        = '^[[19~'
key[F9]        = '^[[20~'
key[F10]       = '^[[21~'
key[F11]       = '^[[23~'
key[F12]       = '^[[24~'

key[Shift-F1]  = '^[[25~'
key[Shift-F2]  = '^[[26~'
key[Shift-F3]  = '^[[28~'
key[Shift-F4]  = '^[[29~'
key[Shift-F5]  = '^[[31~'
key[Shift-F6]  = '^[[32~'
key[Shift-F7]  = '^[[33~'
key[Shift-F8]  = '^[[34~'

key[Insert]    = '^[[2~'
key[Delete]    = '^[[3~'
key[Home]      = '^[[1~'
key[End]       = '^[[4~'
key[PageUp]    = '^[[5~'
key[PageDown]  = '^[[6~'
key[Up]        = '^[[A'
key[Down]      = '^[[B'
key[Right]     = '^[[C'
key[Left]      = '^[[D'

key[Bksp]      = '^?'
key[Bksp-Alt]  = '^[^?'
key[Bksp-Ctrl] = '^H'    console only.

key[Esc]       = '^['
key[Esc-Alt]   = '^[^['

key[Enter]     = '^M'
key[Enter-Alt] = '^[^M'

key[Tab] = '^I' or '\t' unique form! can be bound, but does not 'showkey -a'.
key[Tab-Alt]   = '^[\t'


'Ctrl+`' == 'Ctrl+2', and 'Ctrl+1' == '1' in xterm.
Several 'Ctrl+number' combinations are void at console, but return codes in xterm. OTOH Ctrl+Bksp returns '^H' at console, but is identical to plain 'Bksp' in xterm. There are no doubt more of these little glitches however, in the main:

White key codes are easy to understand, each of these 'normal' printing keys has six forms:

A            = 'a'    (duhhh)
A-Shift      = 'A'    (who would have guessed?)
A-Alt        = '^[a'
A-Ctrl       = '^A'
A-Alt-Ctrl   = '^[^A'
A-Alt-Shift  = '^[A'
A-Ctrl-Shift = '^A'   (Shift has no effect)

Don't forget that:

/-Shift-Ctrl = Bksp      = '^?'
[-Ctrl       = Esc       = '^['
M-Ctrl       = Enter     = '^M'
I-Ctrl       = Tab       = '^I' or '\t'

And, we can 'stack' keybindings:

  bindkey -s '^Xm' "My mistress\' eyes are nothing like the sun."

... Bind 'Ctrl-X' followed by 'm' to a nice line of poetry.

And we can flirt with madness:

  bindkey -s '^Pletmenot' 'Let me not, to the marriage of true minds'

... but you hafta start something like that with a 'modifier' character. Try it, if you like keyboard shortcuts, you can really go to town.


Where is it written that 'Ctrl-Bksp' gives one code at console, another in in xterm?

Are these assignments changable?

Who designed all this, and what were they thinking at the time?

Why is it 'Alt-Function' to change terminals *at* a terminal, but 'Alt-Ctrl-Function' to change *to* a terminal from GUI?

How/where is 'Alt-Ctrl-Delete' defined?


Messages sorted by: Reverse Date, Date, Thread, Author