In a terminfo description, names beginning with k
denote keys, while other names are used for non-key capabilities. For most keys, there is no readily apparent relationship between the keys and an existing escape sequence, but cursor-keys are the exception.
Whether they are the same or not depends upon the terminal description. For TERM=linux
, they happen to be the same, however a terminal description could be written for the Linux console where they are not.
The distinction is whether the terminal is initialized into application mode or left in the (default/power-up) normal mode. In application mode, the cursor keys would send EscapeO
as a prefix rather than Escape[
.
A little over half (54%) of the terminal descriptions in the ncurses terminal database use application mode, meaning that cuu1
is more often than not different from kcuu1
.
There's another quirk to be aware of: for other cursor movement, such as cud1
, the terminal description may say \n
, while the key for cursor-down would not send that character (see iTerm
for example).
Further reading: