ANSI COMMANDS

Cursor
Position
Display
Modes
Display
Colors & Atrributes
Display
Miscellaneous
Keyboard
Layout

Letters are case sensitive. All ANSI commands start with ESC (27) followed by ] (91).
In commands with a variable number of codes, separate each code with a semicolon, ;.
To insert an ESC character with a text editor may require a special command, (e.g. ctrl-P in EDIT).
Use ECHO command to issue ANSI commands in a batch file.

External Link: American National Standards Institute (ANSI)


Cursor Position Commands
Command Meaning
<ESC>[row;colH Move cursor to specified row col or to home 0;0 if none specified.
<ESC>[row;colF Move cursor to specified row col or to home 0;0 if none specified.
<ESC>[numA Move cursor up num rows or to to first row.
<ESC>[numB Move cursor down num rows or to to last row.
<ESC>[numC Move cursor right num cols or to to last col.
<ESC>[numD Move cursor left num cols or to to first col.
<ESC>[s Save current cursor position.
<ESC>[u Return cursor saved position.

Display Mode Commands
Command Display Mode
<ESC>[0h 40x25 characters, monochrome.
<ESC>[1h 40x25 characters, color.
<ESC>[2h 80x25 characters, monochrome.
<ESC>[3h 80x25 characters, color.
<ESC>[4h 320x200 pixels, 4 color.
<ESC>[5h 320x200 pixels, monochrome.
<ESC>[6h 640x200 pixels, monochrome.
<ESC>[13h 320x200 pixels, color.
<ESC>[14h 640x200 pixels, 16 color.
<ESC>[15h 640x350 pixels, 2 color.
<ESC>[16h 640x350 pixels, 16 color.
<ESC>[17h 640x480 pixels, 2 color.
<ESC>[18h 640x480 pixels, 16 color.
<ESC>[19h 320x200 pixels, 256 color.
Can also use l (lower case L) instead of h
difference is line wrap is turned off.
Miscellaneous Display Commands
Command Meaning
<ESC>[2J Clear screen
<ESC>[K Clear from cursor to end of line
<ESC>[=7h Enable line wrapping
<ESC>[=7l Disable line wrapping

Text Attributes and Colors

<ESC>[code;...;codem
Code Attribute
0 All attributes off
1 Bright or bold characters
4 Underlined characters
(monochrome only)
5 Blinking characters
7 Reverse video
characters
8 Hidden
characters
Code Foreground Color
30 black
31 red
32 green
33 yellow
34 blue
35 magenta
36 cyan
37 white
Code Background Color
40 black
41 red
42 green
43 yellow
44 blue
45 magenta
46 cyan
47 white

Keyboard Layout Customizations
(Some software ignores these customizations)

<ESC>[keycode;keytext;...p
keycode From keycode tables below (some keyboards differ).
Keycodes in smaller font not available on all keyboards.
keytext Either ASCII code, or text enclosed in double quotes.

Key Alone Shift+Key Ctrl+Key Alt+Key
F1 0;59 0;84 0;94 0;104
F2 0;60 0;85 0;95 0;105
F3 0;61 0;86 0;96 0;106
F4 0;62 0;87 0;97 0;107
F5 0;63 0;88 0;98 0;108
F6 0;64 0;89 0;99 0;109
F7 0;65 0;90 0;100 0;110
F8 0;66 0;91 0;101 0;111
F9 0;67 0;92 0;102 0;112
F10 0;68 0;93 0;103 0;113
F11 0;133 0;135 0;137 0;139
F12 0;134 0;136 0;138 0;140
Key Alone Shift+Key Ctrl+Key Alt+Key
Spacebar 32 32
'   " 39 34 0;40
,   < 44 60 0;51
-   _ 45 95 31 0;130
.   > 46 62 0;52
/   ? 47 63 0;53
;   : 59 58 0;39
=   + 61 43 0;131
[   { 91 123 27 0;26
\   | 92 124 28 0;43
]   } 93 125 29 0;27
`   ~ 96 126 0;41
Key Alone Shift+Key Ctrl+Key Alt+Key
A 97 65 1 0;30
B 98 66 2 0;48
C 99 67 3 0;46
D 100 68 4 0;32
E 101 69 5 0;18
F 102 70 6 0;33
G 103 71 7 0;34
H 104 72 8 0;35
I 105 73 9 0;23
J 106 74 10 0;36
K 107 75 11 0;37
L 108 76 12 0;38
M 109 77 13 0;50
Key Alone Shift+Key Ctrl+Key Alt+Key
N 110 78 14 0;49
O 111 79 15 0;24
P 112 80 16 0;25
Q 113 81 17 0;16
R 114 82 18 0;19
S 115 83 19 0;31
T 116 84 20 0;20
U 117 85 21 0;22
V 118 86 22 0;47
W 119 87 23 0;17
X 120 88 24 0;45
Y 121 88 25 0;21
Z 122 89 26 0;44
Key Alone Shift+Key Ctrl+Key Alt+Key
0   ) 48 41 0;129
1   ! 49 33 0;120
2   @ 50 54 0 0;121
3   # 51 35 0;122
4   $ 52 36 0;123
5   % 53 37 0;124
6   ^ 54 94 30 0;125
7   & 55 38 0;126
8   * 56 42 0;127
9   ( 57 40 0;128
Key Alone Shift+Key Ctrl+Key Alt+Key
Enter (keypad) 13 10 0;166
/ (keypad) 47 47 0;142 0;74
* (keypad) 42 0;144 0;78
- (keypad) 45 45 0;149 0;164
+ (keypad) 43 43 0;150 0;55
5 (keypad) 0;76 53 0;143
Key Alone Shift+Key Ctrl+Key Alt+Key
Home   7 0;71 55 0;119
UpArw   4 0;75 52 0;115
RtArw   6 0;77 54 0;116
End   1 0;79 49 0;117
DnArw   2 0;80 50 0;145
PgDn   3 0;81 51 0;118
Ins   0 0;82 48 0;146
7   & 55 38 0;126
Del   . 0;83 46 0;147
PrtScr (gray) 0;114
Scroll Lock (gray) ? ? ? ?
Pause/Break (gray) 0;0
Pause/Break 0;0
Key Alone Shift+Key Ctrl+Key Alt+Key
Backspace (gray) 8 8 127 0
Enter (gray) 13 10 0;28
Tab (gray) 9 0;15 0;148 0;165
Home (gray) 224;71 224;71 224;119 224;151
UpArw (gray) 224;72 224;72 224;141 224;152
PgUp (gray) 224;73 224;73 224;132 224;153
LtArw (gray) 224;75 224;75 224;115 224;155
RtArw (gray) 224;77 224;77 224;116 224;157
End (gray) 224;79 224;79 224;117 224;159
DnArw (gray) 224;80 224;80 224;145 224;154
PgDn (gray) 224;81 224;81 224;118 224;161
Ins (gray) 224;82 224;82 224;146 224;162
Del (gray) 224;83 224;83 224;147 224;163

© 2005 Prem Sobel. All Rights Reserved.