This takes a bit of work. To use the Function Keys in batch files requires "ansi.sys" escape sequences. This is not natively supported in Windows versions anymore, but that's not going to stop us.
===============
FIRST,
we'll have to get ANSI support in your command interpreter. The easiest way to do this is to load the ansi.sys driver when the command shell interpreter starts.
Create an ansi.nt config file in your Windows system directory, like c:\winnt\system32\, with the following lines,
dosonly
device=%systemroot%\system32\ansi.sys
device=%SystemRoot%\system32\himem.sys
files=40
dos=high,umb
yahoo answers might cut off the end of the "device" lines above. They should read (without spaces)
device=%systemroot% \ system32 \ ansi.sys
device=%SystemRoot% \ system32 \ himem.sys
Next, create a shortcut on your desktop to "command.com". Make sure you use "command.com" not "cmd.exe". When the shortcut is on your desktop, then right click it and go to "Properties - Programs - Advanced"
Change the Config filename from the default config file,
%systemroot% \ system32 \ config.nt
to
%systemroot% \ system32 \ ansi.nt
(I put some spaces in so that it displays correctly here. Remove them from the actual file paths)
Now, DOS apps run in this command shell will have ANSI support.
===========
SECOND,
we need to figure out how to use ansi escape sequences and assign them to the Function keys.
ANSI escape sequences have to start with the "ESCape" key. Unfortunately, you can't do this by just pressing the escape key. You need to "echo" it in.
Use the dos "EDIT" program to generate the proper code.
Open "EDIT", then hit "Ctrl-P", the status bar at the bottom will read "Enter the control key to insert". Then press the "ESCape" key. You should see a little arrow. That's the ansi escape code.
Now that you know how to do that ...
==============
THIRD,
The Function Keys have special 'extended' codes which are,
F1 0;59
F2 0;60
F3 0;61
F4 0;62
F5 0;63
F6 0;64
F7 0;65
F8 0;66
F9 0;67
F10 0;68
F11 0;133
F12 0;134
=============
FOURTH,
Finally we'll create a batch file to illustrate using Function keys. For that, we'll use the a code snippet from
http://www.xrmx.com/resources/programming/batch.html
@ECHO OFF
REM Reassign F1 to list current directory
ECHO esc[0;59;"DIR/w/p";13p
REM Reassign F10 to give DOS version
ECHO esc[0;68;"VER";13p
REM Put a menu on the Screen in Bright Yellow
CLS
ECHO esc[1;33m
ECHO esc[12;20HF1 List Current directory
ECHO esc[14;20HF10 Print DOS Version Number
REM Reset display to normal
ECHO esc[0m
========
Remember to use EDIT and to replace "esc" with the Escape sequence I showed earlier.
Finally, name and run your batch file from the command window that we created.
You should see a menu that allows you to hit "F1" to list the DOS version information and "F10" to give you a directory listing.
=========
Here's some screens to illustrate these steps,
http://www.flickr.com/photos/97488677@N00/sets/72157600936936709/
2007-07-21 02:40:52
·
answer #1
·
answered by Kevin 7
·
6⤊
0⤋