Simulating keystrokes to a MS-DOS window

Posted on 2000-03-21
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 800 total points
ID: 2654915

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

777 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