Simulating keystrokes to a MS-DOS window

Posted on 2000-03-21
Last Modified: 2010-04-04
I would like to send keys to an MS-DOS window, truely simulating the action of a user on the window.
I've tried with Keybd_event but it doesn't work (it works with standard windows).


Alexandre Guillien
Question by:AGuillien
  • 3
LVL 13

Expert Comment

ID: 2640143
I think you need to send messages to the window handle:

SendMessage(hwnd, WM_KEYDOWN, nVirtKey, lKeyData);


SendMessage(hwnd, WM_KEYUP, nVirtKey, lKeyData);
LVL 13

Expert Comment

ID: 2640152

Expert Comment

ID: 2640154
Hi Alexandre

This might not be what you want but take a look at:

it's supposed to take keystrokes from a supplied text file.

Cheers - Walter McKie

Expert Comment

ID: 2643464
Using Keybd_event will work on a DOS window if you use AttachThreadInput as well. The problem is with some MS-DOS apps that sending Windows messages won't work.

I think the main reason is the vast number of "ill-behaved" MS-DOS apps made in the 80's. A lot of programmers (and programming tools) used BIOS calls to read keystrokes to get complete control over the keyboard. I don't think you can synthesize keystokes for this kind of apps using Windows calls - you'll have to generate BIOS "messages". This shouldn't be too much trouble provided you can find the documentation...

If all else fails - follow this tip.

LVL 13

Accepted Solution

Epsylon earned 200 total points
ID: 2654915

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 263
Delphi - replicating a form 8 65
Dev Express grid collapse 2 39
tidtcpserver connection lost handle 2 70
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now