3

I am new to batch files and I need to write one for a program that runs in DOS. One of the questions on the prompt requires a function key command (i.e. F1, F2, etc).

I've read an article that says you cannot send function keys or alt+key combinations in DOS. Although I have also read an article that says the "Special Extended Code" for function keys are as follows:

F1: 0;59
F2: 0;60
etc...

So my question is, can you send function key commands to DOS? If so, what is the best way to do this?

1

1 Answer 1

1

Here's the example from your link

@ECHO OFF
REM     Reassign F1 to list current directory
REM     Reassign F10 to give DOS version

ECHO ←[0;59;"DIR/w/p";13p
ECHO ←[0;68;"VER";13p

REM     Now Put a menu on the Screen in Bright Yellow
CLS
ECHO ←[1;33m
ECHO ←[12;20HF1                   List Current directory
ECHO ←[14;20HF10                  Print DOS Version Number

REM     Reset display to normal
ECHO ←[0m

(note ← stands for the Escape character, entered using Ctrl+P then Esc inside the DOS EDIT command or Windows command-prompt EDIT command)

You asked

So my question is, can you send function key commands to DOS?

If the example works, yes you can. You may in fact be running Windows and not DOS, which may change things. Can you explain what happened when you tried the batch file above?

When you write "send function key commands" you might have something different in mind. If so it would be useful for you to explain what you want to achieve in a little more detail.

If so, what is the best way to do this?

I don't know, but the method in the article seems reasonable (if limited in applicability).

2
  • ECHO ←[0;59;"DIR/w/p";13p This command from my understand reassigns F1 to DIR/w/p When the program runs it comes to a point where it waits for user input. The usual input is "F1". It goes through a few more prompts where the user inputs (y/n). Since that command is reassigning. Could I possibly reassign a key to represent F1? (i.e. ECHO ←[some key;0;59;13p) I'm not sure how else to describe what I am wanting to do other than the screen prompts the users input of F1 and then a series of (y/n). I'd like to create a batch file that will send F1 when asked and then answer y/n.
    – megantb
    Aug 22, 2011 at 17:57
  • No, using this technique you can't do that. If what you want to do is control an existing interactive DOS program, you need a special program like "expect" - I don't know of a version for MS-DOS but there is probably something equivalent. Aug 22, 2011 at 19:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .