Sending function keys (F1-F12) over SSH

Terminals only understand characters, not keys. So al function keys are encoded as sequences of characters, using control characters. Apart from a few common ones that have an associated control character (Tab is Ctrl+I, Enter is Ctrl+M, Esc is Ctrl+[), function keys send escape sequences, beginning with Ctrl+[ [ or Ctrl+[ O. You can use the tput command to see what escape sequence applications expect for each function key on your terminal. These sequences are stored in the terminfo database. For example, the shell snippet below shows the escape sequences corresponding to each function key.

$ for x in {1..12}; do echo -n "F$x "; tput kf$x | cat -A; echo; done
F1 ^[OP
F2 ^[OQ
F3 ^[OR
F4 ^[OS
F5 ^[[15~
F6 ^[[17~
F7 ^[[18~
F8 ^[[19~
F9 ^[[20~
F10 ^[[21~
F11 ^[[23~
F12 ^[[24~

Another way to see the escape sequence for a function key is to press Ctrl+V in a terminal application that doesn't rebind the Ctrl+V key (such as the shell). Ctrl+V inserts the next character (which will be the escape character) literally, and you'll be able to see the rest of the sequence, which consists of ordinary characters.

Since the sequences may be awkward to type, do investigate changing the key bindings in your application or using another terminal emulator. Also, note that you may have a time limit: some applications only recognize escape sequences if they come in fast enough, so that they can give a meaning to the Esc key alone.


Android Terminal Emulator by Jack Palevich uses key combinations with the volume keys to send a variety of keys, including function keys. There is also Hacker's Keyboard which has every key available that a real keyboard would have.