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:-
|01||1||A||SOH||Start of header •|
|02||2||B||STX||Start of text •|
|03||3||C||ETX||End of text •|
|04||4||D||EOT||End of transmission •|
|0C||12||L||FF||Form feed (new page)|
|0D||13||M||CR||Carriage Return (non-marking)|
|11||17||Q||DC1||Device control 1 •|
|12||18||R||DC2||Device control 2|
|13||19||S||DC3||Device control 3 •|
|14||20||T||DC4||Device control 4|
|15||21||U||NAK||Negative acknowledge •|
|17||23||W||ETB||End of text block •|
|19||25||Y||EM||End of medium •|
|1C||28||\||FS||File separator •|
|1D||29||]||GS||Group separator •|
|1E||30||~||RS||Record separator •|
|1F||31||_||US||Unit separator •|
• Rarely used within data files
* Not available on a Mac OS computer
DEL, in the same way as code
127. Similarly, codes
159, when not used for characters, can have the same effect as codes
RS. Note that Ctrl-^ is often used to generate the
^character itself, whilst
RSis sometimes be obtained by pressing Ctrl->, with
USgenerated by pressing Ctrl-?. In some instances,
DELis sent as a special sequence of codes.
USwhen you press Ctrl at the same time as ⇠, ⇢, ⇡ or ⇣ respectively.
Control codes are rarely found inside modern documents, especially
EOT, as used in a communications link to mark the boundaries of text data,
NAK, which are used to check the presence of data passing over such a link, and
CAN, which maintain basic communications control. In addition,
SI can be used to instruct a printer to use double-width, compressed-width or an alternative character set,
DC4 can select other printer modes, whilst
US can be used as a form of punctuation for non-textual data.
Some software and computer systems use selected codes as follows:-
|Ctrl-C||Aborts the current operation (Interrupt) •|
|Ctrl-H||Deletes the last typed character (Backspace)|
|Ctrl-I||Completes file and folder names|
|Ctrl-O||Stops current communication (Abort output)|
|Ctrl-Q||Continues current communication (XON)|
|Ctrl-S||Pauses current communication (XOFF)|
|Ctrl-M||Terminates a command entry and starts its execution|
|Ctrl-Z||Marks the End of file (EOF) for a text file|
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:-
|Hex||Dec||Name||Standard Keys||Mac Key(s)||Mac Menu Symbol|
|05||5||ENQ||Ctrl-E||Help or Insert||⇧|
|10||16||DEL||Ctrl-P||F1 to F15||⇣|
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
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
27) followed by
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:-
|Find||ESC [ 1 ~||F6||ESC [ 17 ~||F14||ESC [ 26 ~|
|Ins||ESC [ 2 ~||F7||ESC [ 18 ~||F15||ESC [ 28 ~|
|Remove||ESC [ 3 ~||F8||ESC [ 19 ~||F16||ESC [ 29 ~|
|Sel||ESC [ 4 ~||F9||ESC [ 20 ~||F17||ESC [ 31 ~|
|Prev||ESC [ 5 ~||F10||ESC [ 21 ~||F18||ESC [ 32 ~|
|Next||ESC [ 6 ~||F11||ESC [ 23 ~||F19||ESC [ 33 ~|
|F12||ESC [ 24 ~||F20||ESC [ 34 ~|
|F13||ESC [ 25 ~|
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.