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).
There are 2 techniques which will send keystrokes to an MS DOS program
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.
I have not found any Delphi command to perform this function.