Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

share|improve this question
Note that the WWW site that you point to is in this case discussing DOS, not Windows, nor even a VDM within Windows. Unless you truly are running your program on DOS, you've started from a WWW site discussing the wrong thing. And even if you are truly using DOS, you've begun from a misunderstanding of what a "batch file" is. Try modifying your question to focus squarely on the actual goal that you want to achieve, rather than on a subtask and a tool that is likely unsuitable. – JdeBP Aug 24 '11 at 0:19

Here's the example from your link

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
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).

share|improve this answer
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 '11 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. – RedGrittyBrick Aug 22 '11 at 19:20

You must log in to answer this question.

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