key pressing emulation with CreateProces

key pressing emulation with CreateProces

Imagen de Community Admin

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

publicaciones de 4 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Imagen de Jugoslav Dujic

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
Imagen de Community Admin

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

Imagen de Jugoslav Dujic

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

Inicie sesión para dejar un comentario.