key pressing emulation with CreateProces

key pressing emulation with CreateProces

Dear all,

How can I simulate a key press event (Esc) on a console
application started using CreateProcess?

I have a dll, that calls an .exe
(like the fem.exe example discussed previously)
I want to limit the run time, by using WaitForSingleObject.
Ok, that exe can be stopped nicely by pressing Esc.
If I just kill the process, the output file is not finished.

How can I "press Esc" from my calling DLL?

Simo

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Don't have a finished answer -- just a couple of suggestions:

1) Try using WriteConsoleInput->INPUT_RECORD->KEY_EVENT_RECORD. The first argument (hConsoleInput) should come from STARTUPINFO%hStdInput you put into CreateProcess.

2) You may also try GenerateConsoleCtrlEvent.

3) keybd_event may well be the simplest method, although for that to work the console has to have keyboard focus.

HTH

Jugoslav

Jugoslav
www.xeffort.com

Jugoslav wrote:
> 1) Try using WriteConsoleInput->INPUT_RECORD->KEY_EVENT_RECORD.

Yes, I tried that some time ago. The problem is: If I set
si%dwFlags = IOR (si%dwFlags, STARTF_USESTDHANDLES),
that is necessary for the use of StdInput handle, the exe doesn't run
at all. Maybe it can't write to stdout anymore, or something?
Don't know.

And GenerateConsoleCtrlEvent can only create Ctrl-C
and Ctrl-BREAK events, not Esc.

Simo

As I said, my answer was based solely on docs -- I thought handles would be returned even if you don't set STARTF_USESTDHANDLES. If that's not the case, try specifying STARTF_USESTDHANDLES and fill in the members of STARTUPINFO using GetStdHandle (you have to specify bInheritHandles=.TRUE. for CreateProcess).

Jugoslav
www.xeffort.com

Leave a Comment

Please sign in to add a comment. Not a member? Join today