Although most kinds of text file only contain text, it’s also possible to send additional information, usually related to the transmission or presentation of the text itself. This is commonly sent in the form of control codes or escape sequences.
All of the two or three-letter mnemonics in a computer’s character set represent control codes. Most modern computers and terminals, automatically generate these codes when you press a key, such as the Ctrl (Control) key, at the same time as a given ASCII character key.
The control codes defined by the ASCII standard are listed below:-
Hex | Dec | Name | Function | |
---|---|---|---|---|
00 | 0 | @ | NUL | Null |
01 | 1 | A | SOH | Start |
02 | 2 | B | STX | Start |
03 | 3 | C | ETX | End |
04 | 4 | D | EOT | End |
05 | 5 | E | ENQ | Enquire |
06 | 6 | F | ACK | Acknowledge |
07 | 7 | G | BEL | Bell |
08 | 8 | H | BS | Backspace |
09 | 9 | I | HT | Horizontal |
0A | 10 | J | LF | Line |
0B | 11 | K | VT | Vertical |
0C | 12 | L | FF | Form |
0D | 13 | M | CR | Carriage |
0E | 14 | N | SO | Shift |
0F | 15 | O | SI | Shift |
10 | 16 | P | DEL | Delete |
11 | 17 | Q | DC1 | Device |
12 | 18 | R | DC2 | Device |
13 | 19 | S | DC3 | Device |
14 | 20 | T | DC4 | Device |
15 | 21 | U | NAK | Negative |
16 | 22 | V | SYN | Synchronise |
17 | 23 | W | ETB | End |
18 | 24 | X | CAN | Cancel |
19 | 25 | Y | EM | End |
1A | 26 | Z | SUB | Substitute |
1B | 27 | [ | ESC | Escape |
1C | 28 | \ | FS | File |
1D | 29 | ] | GS | Group |
1E | 30 | ~ | RS | Record |
1F | 31 | _ | US | Unit |
7F | 127 | ! | DEL | Delete |
• Rarely used within data files
* Not available on a Mac OS computer
255
acts as DEL
, in the same way as code 127
. Similarly, codes 128
to 159
, when not used for characters, can have the same effect as codes 0
to 31
.RS
. Note that Ctrl-^ is often used to generate the ^
character itself, whilst RS
is sometimes be obtained by pressing Ctrl->, with US
generated by pressing Ctrl-?. In some instances, DEL
is sent as a special sequence of codes.FS
, GS
, RS
or US
when you press Ctrl at the same time as ⇠, ⇢, ⇡ or ⇣ respectively.Control codes are rarely found inside modern documents, especially SOH
, STX
, ETX
and EOT
, as used in a communications link to mark the boundaries of text data, ACK
and NAK
, which are used to check the presence of data passing over such a link, and ENQ
, SYN
, ETB
and CAN
, which maintain basic communications control. In addition, SO
and SI
can be used to instruct a printer to use double-width, compressed-width or an alternative character set, DC1
to DC4
can select other printer modes, whilst FS
, GS
, RS
and US
can be used as a form of punctuation for non-textual data.
Some software and computer systems use selected codes as follows:-
Code | Effect |
---|---|
Ctrl-C | Aborts |
Ctrl-H | Deletes |
Ctrl-I | Completes |
Ctrl-O | Stops |
Ctrl-Q | Continues |
Ctrl-S | Pauses |
Ctrl-M | Terminates |
Ctrl-Z | Marks |
Ctrl-Q and Ctrl-S, are specifically used in a computer terminal to pause and resume long listings of text on the screen. You simply press Ctrl-S when you spot something you want to read and then press Ctrl-Q to continue the listing, or you can press Ctrl-C to abort the entire process.
Computer operating systems often use control codes for various purposes ‘behind the scenes’. For example, many of the keys on a Mac OS keyboard generate special character codes that are actually control codes. Similarly, the special font characters that appear in Classic Mac OS menus are identified by control codes, although these are unrelated to the original purposes of the codes.
The following table provides further details, including Mac OS symbols:-
Hex | Dec | Name | Std | Mac | |
---|---|---|---|---|---|
01 | 1 | SOH | Ctrl-A | Home | ![]() |
02 | 2 | STX | Ctrl-B | - | ⇥ |
03 | 3 | ETX | Ctrl-C | Enter | ⇤ |
04 | 4 | EOT | Ctrl-D | End | ![]() |
05 | 5 | ENQ | Ctrl-E | Help | ⇧ |
06 | 6 | ACK | Ctrl-F | - | ⌃ |
07 | 7 | BEL | Ctrl-G | - | ⌥ |
08 | 8 | BS | Ctrl-H | Delete | |
09 | 9 | HT | Ctrl-I | Tab | |
0A | 10 | LF | Ctrl-J | - | ![]() |
0B | 11 | VT | Ctrl-K | Page | ![]() |
0C | 12 | FF | Ctrl-L | Page | ![]() |
0D | 13 | CR | Ctrl-M | Return | |
0E | 14 | SO | Ctrl-N | - | ![]() |
0F | 15 | SI | Ctrl-O | - | ![]() |
10 | 16 | DEL | Ctrl-P | F1 | ⇣ |
11 | 17 | DC1 | Ctrl-Q | - | ⌘ |
12 | 18 | DC2 | Ctrl-R | - | √ |
13 | 19 | DC3 | Ctrl-S | - | ◆ |
14 | 20 | DC4 | Ctrl-T | - | ![]() |
15 | 21 | NAK | Ctrl-U | - | ![]() |
16 | 22 | SYN | Ctrl-V | - | ![]() |
17 | 23 | ETB | Ctrl-W | - | ![]() |
18 | 24 | CAN | Ctrl-X | - | ⇠ |
19 | 25 | EM | Ctrl-Y | - | ⇡ |
1A | 26 | SUB | Ctrl-Z | - | ⇢ |
1B | 27 | ESC | Ctrl-[ | Esc | ⎋ |
1C | 28 | FS | Ctrl-\ | ⇠ | ⌧ |
1D | 29 | GS | Ctrl-] | ⇢ | |
1E | 30 | RS | - | ⇡ | ![]() |
1F | 31 | US | - | ⇣ | ![]() |
7F | 127 | DEL | - | Fwd | ![]() |
Standard coding systems don’t provide for sending instructions to another device, such as a printer or modem. However, such instructions can be accommodated inside an escape sequence, usually consisting of an ESC
control code (decimal 27
, hex 1B
) followed by a string of data bytes. To be effective, each sequence must include the correct number of bytes.
The notation used for an escape sequence is quite simple. For example, the instruction ESC ! BS
is actually made up of ESC
(decimal 27
) followed by !
(decimal 33
) and BS
(decimal 8
). Sequences sometimes include control codes, as in, for example, ESC EM R
, where EM
is the control code.
Escape sequences can be used to accommodate non-standard keys on a keyboard where other control codes can’t be used. For example, a standard VT220 terminal can use the following sequences to accommodate special keys, including the function keys from F6 to F20, as found on modern keyboards:-
Key | Sequence | Key | Sequence | |
---|---|---|---|---|
Find | ESC [ 1 ~ | F6 | ESC [ 17 ~ | |
Ins | ESC [ 2 ~ | F7 | ESC [ 18 ~ | |
Rmv | ESC [ 3 ~ | F8 | ESC [ 19 ~ | |
Sel | ESC [ 4 ~ | F9 | ESC [ 20 ~ | |
Prev | ESC [ 5 ~ | F10 | ESC [ 21 ~ | |
Next | ESC [ 6 ~ | F11 | ESC [ 23 ~ | |
F12 | ESC [ 24 ~ | |||
F13 | ESC [ 25 ~ |
Key | Sequence |
---|---|
F14 | ESC [ 26 ~ |
F15 | ESC [ 28 ~ |
F16 | ESC [ 29 ~ |
F17 | ESC [ 31 ~ |
F18 | ESC [ 32 ~ |
F19 | ESC [ 33 ~ |
F20 | ESC [ 34 ~ |
Escape sequences can be used to control an older type of dot-matrix printer, although there is considerable variation in the interpretation of such codes, some of which operate with both an Epson (ESC/P) printer or an IBM-compatible printer. Other printer models also use some of these sequences or different codes of their own.
©Ray White 2004.