Remix.run Logo
mprovost a day ago

On terminals, the control key masked off the 6th and 7th bits of the 8-bit value sent by the letter key. That's a bitwise AND with octal 037, or in decimal subtracting 96 from the lower case key value. This happens in the terminal (or keyboard) itself, so the computer doesn't see it as two pressed keys, it just gets the masked value. In ASCII 'c' is 99 (decimal), so when modified with control is 3, ETX (end of text), which teletypes used to indicate the end of text. So unix shells reused that control character to terminate the current program with SIGINT. But every letter key maps to a control character at the start of the ASCII range, like 'g' maps to BEL for the bell, or 'h' maps to BS (backspace). '[' maps to ESC (escape) which is handy when Apple decides to move the escape key on their laptop keyboard.

int_19h 9 hours ago | parent | next [-]

Unless we're talking about ancient hardware terminals, the computer sees the actual raw scancodes coming from the keyboard. Control (whether by itself or in combination with something else) is no different than any other key. It's the software that maps those combinations to ASCII control characters, which is why this works the way you described on most Unices (where, if I remember correctly, it's the tty that is doing the mapping) but not e.g. on DOS/Windows.

tedunangst 20 hours ago | parent | prev [-]

The funny bit is the other six control codes are mapped ctrl-2 to nul, and ctrl-3 forward to the five remaining.