Sending Keys to Dos Applications

It is useful to be able to send keystrokes to MS DOS applications. The old (MS DOS) technique was to stuff the keyboard buffer. There used to be a number of free programs which would do this.

However, MS Windows 95 and latter have effectively disabled this technique. Luckily, Christopher Latta provides the shareware/freeware program PushKeys to emulate key presses. There are VB, Delphi, C, C++ Bulider, and DLL versions of this utility.

I use this procedure to automatically test MS DOS applications.

As of Jan 2004, I can no longer find PushKeys on the internet. Torry's Delphi pages provides a variety of related tools, including TPushKeys (by Alan Warriner) - a component that encapsulates, and extends, Christopher Latta's PushKeys code . (I have not tested TPushKeys, yet.)

As of March 2007, I found a 1997 copy of PushKeys (VB zip file).

Visual Basic | Delphi | C++ Builder

Visual Basic 6.0

Visual Basic provides the SendKeys command to allow one windows program to send keystrokes to another windows program. Unfortunately, this command can not send keys to an MS DOS program.

There are 2 techniques which will send keystrokes to an MS DOS program

The shareware/freeware program PushKeys uses keybd_event to emulate key presses instead of the WM_CHAR message that SendKeys seems to use.

When reading the keyboard, all key presses except Tab go to the KeyDown event, function and control (arrow) keys then go to KeyUp, and regular ASCII keys (a-z, A-Z, 0-9 ...) go to KeyPress. The Visual Basic 6.0 help says that all of these events call KeyUp. For a standard TextBox control, the help is wrong.

There are several kludges to detect when the Tab key is pressed.

When holding down the Shift key and repeatedly pressing theTab key, only the first Tab will have Shift set to true. The rest will have it false if focus is transfered to a DOS application between Tabs. (This may be a problem with PushKeys. Either way, if the shift key is depressed, the VB application should say so.)

To find the important keyboard constants, search for Keycode Constants. The constant names are different between VB 3.0 and VB 6.0 :(

There is a problem using PushKeys to capture a DOS screen (copy it to the clipboard). This kludge works part of the time.


The shareware/freeware program TPushKeys uses keybd_event to emulate key presses.

I have not found any Delphi command to perform this function.

C++ Builder

The shareware/freeware program TPushKeys uses keybd_event to emulate key presses.

Author: Robert Clemenzi -
URL: http:// / user / clemenzi / technical / Languages / DOSSendKeys.htm