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.

4
  • There has traditionally been a page for ascii in section 7 of the Unix user manual. (-:
    – JdeBP
    Oct 12 '16 at 17:32
  • 1
    Yes, I've seen it (assuming your'e talking about man ascii). It doesn't say anything about keystrokes.
    – user628544
    Oct 12 '16 at 17:35
  • I was addressing your worries about topicality.
    – JdeBP
    Oct 12 '16 at 17:43
  • Is man console_codes usefull?
    – user147505
    Oct 12 '16 at 17:50
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.

1
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 }'
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.

1
  • It is better to edit your previous answers if something was not correct.
    – jimmij
    Feb 8 '19 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.