Determine Escape Sequence Key Codes

SecureCRT


If you need to determine the escape sequence for a particular key that a terminal emulator sends to a remote system (e.g., for use in scripting or custom key mappings), there are a couple of ways to do this.

Using any terminal emulator, connect to a remote system running UNIX. You should be able to use the following command from your shell to determine what sequence of characters the remote system receives when a particular key is pressed:

cat –v

For example, if you press the PF1 key from a VT100 terminal (or an emulator which maps the PF1 key), you should see:

^[OP

(This is typically read: ESC O P.)

In SecureCRT, using the VT100 keyboard emulation, this can be sent by pressing the NUM LOCK key.

Using SecureCRT's ActiveX scripting support with VBScript, you could send this sequence using the following command string:

crt.Screen.Send Chr(27) & "OP"

Using SecureCRT's Python scripting support, you could send this sequence using the following command string:

crt.Screen.Send(chr(27) + "OP")

In the examples above, "27" is the ASCII decimal value for the ESC character.

Similarly, in SecureCRT's Session Options/Terminal/Emulation/Mapped Keys dialog or Keymap Editor, you can use "\e" to represent the ESC character, or use the octal ASCII value "\033". More information about this can be found in the Table of Keymap Functions and Send String and Function Key Commands sections.

Using the Keymap Editor, you can also find out the default mappings for the keys you press. For example, with the VT100 keymap loaded, clicking on the F1 button in the Keymap Editor will show you "VT_PF1", which is an internal alias for the sequence "ESC O P" (or "^[OP", "\033OP", etc.).

It is important to understand that there are no absolute values that any particular key sends, so what one remote system accepts for PF1 may not be consistent on a different system. Moreover, there are many ways of representing the same escape sequence, including decimal (e.g., "Chr(27)" in VBScript), backslash escape characters (e.g., "\e" for ESC in SecureCRT), and octal (e.g., "\033OP" or "\033\117\120").