We help IT Professionals succeed at work.

Simulate Key Strokes to a Dos program

lmarceau asked
Last Modified: 2006-11-17
How can a simulate key strokes to a Dos Program running under Windows95?

My app need to lunch an app and time a five minutes delay before it ask it to quit, usualy by sending key strokes in series like "alt-x, n" or "F10, Y". My user will tell the corect sequence to send. But I must know how to send them!

ps: I know it can be done, the ScriptTools and ScriptRunner of PcTools 2.0 for Windows 3.1 does it wonderfully under both 3.1 and 95.
Watch Question

Hummm... 16-bits I'm not sure of, 32-bits I might have a solution for. One question, though, do you need to be able to send just *some* keystrokes? I've already written a 32-bit class allowing you to redirect *all* input/output to/from a console/dos app, if you need to control only parts of the input it won't do.




Edited text of question
This one is on us!
(Get your first solution completely free - no credit card required)


I've copy/pasted your code in Delphi developper 2.0.
The console boot ok. Prety cool right.
But the key aren't sent. Can you find out why?

Win 95 or NT ?? Version?

Are the path and filename in CreateProcess correct?

What return values do you get from CreateProcess and WriteConsoleInput? What are the values returned if calling  GetLastError after these calls?




Escuse me for the delay. I'm back now.

The answers to your questions are:
I'm under Win95, Delphi 2.0

While running your code:
Console created ok
Process created ok in the console ('c:\command.com') CreateProcess returns 1, GetLastError (just after the call to createprocess) returns 6  (what does that means? where can I get a list of error code?)

Key not sent (I've added a feed back on the form, 'Sent' is beaing textout on the form every two second but the keys aren't sent)
WriteConsoleInput returns 1, GetLastError (just after the call to WriteConsoleInput) returns 6 too.

Hope this help, my shipping deadline is now aproaching!


Well, my deadline had gone though and I had to ship without the feature/ But a still need a solution.
Please help me. You seem to have a more powerfull solution than anyone else.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.