Special Codes

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.

Control Codes

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:-

HexDecCharNameFunction
000@NULNull *
011ASOHStart of header •
022BSTXStart of text •
033CETXEnd of text •
044DEOTEnd of transmission •
055EENQEnquire •
066FACKAcknowledge •
077GBELBell
088HBSBackspace
099IHTHorizontal tabulation
0A10JLFLine feed
0B11KVTVertical tabulation
0C12LFFForm feed (new page)
0D13MCRCarriage Return (non-marking)
0E14NSOShift out
0F15OSIShift in
1016PDELDelete •
1117QDC1Device control 1 •
1218RDC2Device control 2
1319SDC3Device control 3 •
1420TDC4Device control 4
1521UNAKNegative acknowledge •
1622VSYNSynchronise •
1723WETBEnd of text block •
1824XCANCancel
1925YEMEnd of medium •
1A26ZSUBSubstitute •
1B27[ESCEscape
1C28\FSFile separator •
1D29]GSGroup separator •
1E30~RSRecord separator •
1F31_USUnit separator •
7F127!DELDelete

Rarely used within data files

* Not available on a Mac OS computer

Unusual Codes

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.

Using Control Codes

Some software and computer systems use selected codes as follows:-

CodeEffect
Ctrl-CAborts the current operation (Interrupt) •
Ctrl-HDeletes the last typed character (Backspace)
Ctrl-ICompletes file and folder names
Ctrl-OStops current communication (Abort output)
Ctrl-QContinues current communication (XON)
Ctrl-SPauses current communication (XOFF)
Ctrl-MTerminates a command entry and starts its execution
Ctrl-ZMarks the End of file (EOF) for a text file
Has a similar effect to pressing Break or Ctrl-Scroll Lock on a PC

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.

Non-Standard Uses for Control Codes

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:-

HexDecNameStandard Keys Mac Key(s)Mac Menu Symbol
011SOHCtrl-AHome
022STXCtrl-B-
033ETXCtrl-CEnter
044EOTCtrl-DEnd
055ENQCtrl-EHelp or Insert
066ACKCtrl-F-
077BELCtrl-G-
088BSCtrl-HDelete 
099HTCtrl-ITab 
0A10LFCtrl-J-
0B11VTCtrl-KPage Up
0C12FFCtrl-LPage Down
0D13CRCtrl-MReturn 
0E14SOCtrl-N-
0F15SICtrl-O-
1016DELCtrl-PF1 to F15
1117DC1Ctrl-Q-
1218DC2Ctrl-R-
1319DC3Ctrl-S-
1420DC4Ctrl-T-
1521NAKCtrl-U-
1622SYNCtrl-V-
1723ETBCtrl-W-
1824CANCtrl-X-
1925EMCtrl-Y-
1A26SUBCtrl-Z-
1B27ESCCtrl-[Esc
1C28FSCtrl-\
1D29GSCtrl-] 
1E30RS-
1F31US-
7F127DEL-Forward Delete

Escape Sequences

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.

Terminal Sequences

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:-

KeySequence KeySequence KeySequence
FindESC [ 1 ~ F6ESC [ 17 ~ F14ESC [ 26 ~
InsESC [ 2 ~ F7ESC [ 18 ~ F15ESC [ 28 ~
RemoveESC [ 3 ~ F8ESC [ 19 ~ F16ESC [ 29 ~
SelESC [ 4 ~ F9ESC [ 20 ~ F17ESC [ 31 ~
PrevESC [ 5 ~ F10ESC [ 21 ~ F18ESC [ 32 ~
NextESC [ 6 ~ F11ESC [ 23 ~ F19ESC [ 33 ~
   F12ESC [ 24 ~ F20ESC [ 34 ~
   F13ESC [ 25 ~   

Printer Control Sequences

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.