1

Okay, so I've recently realized the correspondence between Control keystrokes and ASCII control codes, e.g. ^D sends the EOT character because EOT is ASCII code 4 and D is the fourth letter in the alphabet. I'm wondering what would be the keystrokes for characters beyond 26 decimal, i.e. ESC, FS, GS, RS, and US. Does the Escape key send the ESC character? What about the default ^] keystroke in Telnet that escapes to the shell. Does that send the ESC character?

And I apologize if this is off-topic. I couldn't find anywhere else to put it.

user628544
  • 1,565

4 Answers4

2

The keystrokes for the further control characters are as follows:

^[ - Escape
^\ - File Separator
^] - Group Separator
^^ - Record Separator
^_ - Unit Separator

telnet uses the group separator as its escape to its interactive interface. As the escape character is often used in terminal applications, it is typically sent through to the far-side to which the telnet connection is established.

DopeGhoti
  • 76,081
2

From ascii(7) on Linux reading across rows, for ^D using your correspondence we find:

   004   4     04    EOT (end of transmission)   104   68    44    D

And then for ^] using that very same correspondence:

   035   29    1D    GS  (group separator)       135   93    5D    ]

This can additionally be confirmed by placing the terminal into raw mode, and printing out the hex code of the key mashed, then looking up the hex code in ascii(7):

perl -MTerm::ReadKey -e 'warn "PID $$\n"; $SIG{TERM}=sub {ReadMode 0; exit};' \
  -e 'ReadMode 4; while ($k=ReadKey(0)) { printf "%02x\n", ord $k }'
thrig
  • 34,938
0

Back when keyboards sent ASCII codes directly to the keyboard port, yes, Control plus the letter keys and six others produced the ASCII control codes. On IBM-type micros, the keyboard produces scan codes, and the BIOS or the OS reports those and the appropriate ASCII codes (control or graphic) to applications.

0

Oops -- my previous post was not a good answer. In Linux at least, the ASCII code reported for the ESC key is indeed the same as that for Ctrl-[, and that for Enter is the same as that for Ctrl-M. For Backspace, Ctrl-? (DEL) is reported, and for Ctrl-Backspace, Ctrl-H (BS) is reported, but they do the same thing. For the Delete key, an ANSI Escape sequence is reported.