Skip to main content
Version: 4.0

Special Characters

When you're using an interactive shell via $ssh->write() (see Sending Special Characters), printable keys like letters and digits can just be written as themselves. Non-printable keys (arrows, function keys, Ctrl combinations) need to be sent as the byte sequences a real terminal would send.

The sequences below are correct for vt100 (phpseclib's default) and xterm.

Quick reference

KeyString
Ctrl + C"\x03"
Ctrl + D"\x04"
Ctrl + Z"\x1A"
Esc"\x1B"
Tab"\t"
Enter"\n"
Backspace"\x7F"
"\x1B[A"
"\x1B[B"
"\x1B[C"
"\x1B[D"
Home"\x1B[H"
End"\x1B[F"
Page Up"\x1B[5~"
Page Down"\x1B[6~"
Insert"\x1B[2~"
Delete"\x1B[3~"
F1"\x1BOP"
F2"\x1BOQ"
F3"\x1BOR"
F4"\x1BOS"
F5"\x1B[15~"
F6"\x1B[17~"
F7"\x1B[18~"
F8"\x1B[19~"
F9"\x1B[20~"
F10"\x1B[21~"
F11"\x1B[23~"
F12"\x1B[24~"

Why F1–F4 look different from F5+

F1 through F4 use \x1BO (uppercase letter O) as the introducer; F5 onward use \x1B[. This is a holdover from the original VT100 keyboard, which had four function keys distinct from the rest. Modern terminals keep the split for backward compatibility.

If your server-side program isn't responding to a sequence you sent, double-check the terminal type with $ssh->setTerminal(...). Sequences for vt220, linux, and others can differ from the table above.