Once Ansi.sys has been loaded, it's various functions can be accessed at any time by sending one or more "Escape Sequences" to the screen. An Escape Sequence comprises three parts:
|The Prefix||This is the two characters represented by ASCII 27 followed by ASCII 91. ASCII 27 is the character returned by the "ESC" key and is represented in the tables below by . ASCII 91 is the left hand square bracket "[".|
|The Codes||Depending on the actual command, these will be a series of numbers or characters that define the new screen colour, keyboard key, or whatever. The default code is 0 and, when that value is specified, can be omitted.|
|The Suffix||A single letter (case sensitive) that defines how Ansi.sys interprets the Codes. ie. whether the cursor is to be moved, a key to be reassigned or whatever.|
Note that an "Escape Sequence" cannot be entered directly - see: Entering "Escape Sequences" for further details.
Setting Text and Background Colours
| Colour||ANSI Code|
|All attributes off||[||0||m|
|Reverse video characters||7|
A series of colour/attribute commands can be combined into one by separating the codes with semicolons.
Colour changes only take effect as each character is written following the Ansi command. To change the whole screen to the new colours, add the "2J" sequence to clear the screen (see under Miscellaneous, below) or simply enter CLS on the next line.
To change the colours to blinking bright green characters on a cyan background:
ECHO [46m [32m [5m [1m [2J
or, more efficiently:
To change the Display Mode:
||=5||h||320 x 200||Monochrome|
|=6||640 x 200||Monochrome|
|=15||640 x 350||2 Colour|
|=17||640 x 480||2 Colour|
I have no real experience with these modes but they rather look as though they are a hangover from the early days of Dos. I cannot think of any situation where changing display mode to one of the above values would be to any advantage.
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. This can include DOS commands.
- Complete remapping of the keyboard - for special data entry functions or obscure foreign language use, perhaps.
||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.|
This can be:
- The ASCII code for a single character;
- The code associated with a key; or
- a text string (of one or more characters) enclosed in inverted commas.
- Most DOS programs (including EDIT) bypass the standard DOS calls when accepting keyboard input and so will ignore Ansi.sys reassignments.
- Have a care when assigning environmental variables to a key as these will be parsed as they are fed to the screen. Thus, assigning "ECHO %ESC%[" to a key leaves you with just "[" as the "ECHO" is cleared from the command line by %ESC%. However, it is possible to assign two keys to this: the first is assigned "ECHO %ESC", and the second is assigned "%[". Pressing the two keys sequentially puts "ECHO %ESC%[" onto the command line.
- To assign á to the Alt-A key:
- To disable Ctrl-C, assign it to ASCII 255 (Nul)
- To re-enable Ctrl-C, assign it back to 3:
- To assign "FOR %v IN ( ) DO " to Alt-F and have Alt-D append a directory listing of Drive D: to DirD.txt, you have several options including:
- Use EDIT to create a file called "Keys.txt" containing the following lines:
[0;33;"FOR %v IN ( ) DO "p
[0;32;"DIR D: /S >> DirD.txt";13p
(where is inserted using Ctrl-P followed by the "ESC" key).
- Copy Keys.txt to the screen using either:
TYPE Keys.txt or
COPY Keys.txt CON
- Use EDIT to create "Keys.bat" containing the lines:
ECHO [0;33;"FOR %v IN ( ) DO "p
ECHO [0;32;"DIR D: /S >> DirD.txt";13p
- Run the batch file by entering "Keys" at the command line prompt.
Either way, the keys will now be reassigned.