Ansi.sys

Index

Ansi.sys is an enhancement of the "CON" device driver built into Command.com. It can be used to modify the default display colours, the starting position of the cursor, and the mapping of keys. It can also be used to change the video mode.

Syntax

Ansi.sys can only be loaded in Config.sys using a Device or DeviceHigh statement:

Device=[Path]Ansi.sys [/X] [/K] [/R] or
DeviceHigh=[Path]Ansi.sys [/X] [/K] [/R]

[Path] The full path. Default is the root directory of the start-up drive (usually C:/)
/X Enables remapping of the extended keys on a 101-key keyboard.
/K Causes a 101-key keyboard to behave as an 84-key keyboard.
/R Reduces the scrolling speed when long documents are printed to the screen.

Notes

For reasons beyond my comprehension, the designers of ANSI.SYS decided that all commands issued to it would be prefixed with the ASCII code assigned to the "Esc" key followed by an opening square bracket ( [ ). Unfortunately, the designers of Command.com had already reserved the "Esc" key as a means of cancelling the current command line. It is thus impossible to send an ANSI.SYS command directly from the DOS command line. Three ways to overcome this rather peculiar conflict have been developed:

  • Use the PROMPT command along with the "$E" special character.
    Although primarily used for generating fancy/informative prompts, usually in Autoexec.bat, the PROMPT approach is handy for quick-and-dirty testing of sequences from the command line. After using PROMPT this way, don't forget to reset the prompt when done!

    For examples, see PROMPT.

  • As mentioned above, entering the "ESC" character on the command line causes the command to be cancelled. However, when a file containing the "ESC" character is copied to the screen (using the TYPE or COPY filename CON commands) or is encountered in a batch file, the character is accepted for what it is and the command/statement is processed without a hitch. Thus Ansi.sys sequences can be sent to CON either via a text file or a batch file. In either case it is necessary to use a text editor that can handle the "ESC" character.

    Text EditorTo enter the "ESC" characterDisplays as:
    EditCtrl-P followed by "ESC"Left arrow

Examples

To assign "COPY" to Alt-C and "DIR c:\data" to Alt-D:
    1. Use EDIT to create Keys.txt:
       [0;46;"COPY"p [0;32;"DIR c:\data"p
      (where  is inserted using Ctrl-P followed by Esc)
    2. Copy Keys.txt to the screen using either:
      TYPE Keys.txt or
      COPY Keys.txt CON

    Or

    1. Use EDIT to create Keys.bat:
      ECHO  [0;46;"COPY"p
      ECHO [0;32;"DIR c:\data"p
    2. Run the batch file by entering "Keys" at the command line prompt.

Either way, the keys will now be (re)assigned.

The Codes

In all the following, "Esc" indicates the character associated with the "Escape" key on the keyboard. This cannot be entered directly because Command.com interprets this keystroke as a request to abort the command currently being entered.

Ansi.sys codes ARE case specific.

Character Attributes and Colours

ColourANSI Code
TextBackground
Black"Esc"[30m"Esc"[40m
Red"Esc"[31m"Esc"[41m
Green"Esc"[32m"Esc"[42m
Yellow"Esc"[33m"Esc"[43m
Blue"Esc"[34m"Esc"[44m
Magenta"Esc"[35m"Esc"[45m
Cyan"Esc"[36m"Esc"[46m
White"Esc"[37m"Esc"[47m
More than one Attribute/Colour code can be strung together by separating the numbers with semicolons.
For example, underlined green characters with a cyan background can be specified with:
"Esc"[4m"Esc"[32m"Esc"[46m
or, more efficiently:
"Esc"[4;32;46m
Colour/AttributeANSI Code
All attributes off"Esc"[0m
Bright characters"Esc"[1m
Underlined characters"Esc"[4m
Blinking characters"Esc"[5m
Reverse video characters"Esc"[7m
Hidden characters"Esc"[8m

Cursor Positioning

ANSI CodeCursor PositionWhere...
"Esc"[r;cHMoves the cursor to line r and column c
If omitted, r and c both default to 0 (ie. the cursor moves to the top left corner of the screen)
r is the line number
c is the column number
n is an integer
"Esc"[r;cf
"Esc"[nAMoves the cursor up n lines (or top of screen)
"Esc"[nBMoves the cursor down n lines (or bottom of screen)
"Esc"[nCMoves the cursor right n columns (or right hand side of screen)
"Esc"[nDMoves the cursor left n columns (or left hand side of screen)
"Esc"[sSaves current cursor position
"Esc"[uRestores cursor to previously saved position

Miscellaneous

ANSI CodeEffect
"Esc"[2JClears the screen
"Esc"[KClears from the cursor to the end of the line
"Esc"[=7hEnables line wrap
"Esc"[=7lDisables line wrap

To change the Display Mode:

ANSI CodeDisplay Mode
"Esc"[=0hMonochromeText mode40 x 25
"Esc"[=1hColourText mode40 x 25
"Esc"[=2hMonochromeText mode80 x 25
"Esc"[=3hColourText mode80 x 25
"Esc"[=4h4 ColourGraphics mode320 x 200
"Esc"[=5hMonochromeGraphics mode320 x 200
"Esc"[=6hMonochromeGraphics mode640 x 200
ANSI CodeDisplay Mode
"Esc"[=13hColourGraphics mode320 x 200
"Esc"[=14h16 ColourGraphics mode640 x 200
"Esc"[=15h2 ColourGraphics mode640 x 350
"Esc"[=16h16 ColourGraphics mode640 x 350
"Esc"[=17h2 ColourGraphics mode640 x 480
"Esc"[=18h16 ColourGraphics mode640 x 480
"Esc"[=19h256 ColourGraphics mode320 x 200

Keyboard Layout Codes

Ansi.sys can be used to remap the keys of the keyboard. Any key can be redefined to any one or more characters of the extended ASCII character set.
Typical applications of this facility include:

  • Assignment of "non-standard" characters to unused keys
  • Assignment of text phrases to unused keys (including DOS commands)
  • Complete remapping of the keyboard - for special data entry functions or obscure foreign language use, perhaps.

However, most DOS programs bypass the standard DOS calls when accepting keyboard input and so will ignore Ansi.sys reassignments.

Syntax

"Esc"[keycode;stringp

keycode The code(s) associated with the given key. Many keys use a code of two numbers separated by a semicolon and these must be used in full.
string
  • The ASCII code for a single character, or
  • a text string (of one or more characters) enclosed in inverted commas

Examples

  1. To assign á to the Alt-F1 key:
    "Esc"[0;104;193p

File Details

File NameVersionSizeDateDefault Location
Ansi.sysWin95upgrade```
Win95B9,71924/08/96c:\windows\command

If you should have any comments or suggestions,
please contact: Bob Watson
.
This page last revised:
December 9, 1999.