key pressing emulation with CreateProces

key pressing emulation with CreateProces

Аватар пользователя 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?


4 posts / 0 новое
Последнее сообщение
Пожалуйста, обратитесь к странице Уведомление об оптимизации для более подробной информации относительно производительности и оптимизации в программных продуктах компании Intel.
Аватар пользователя 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.



Аватар пользователя 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.


Аватар пользователя 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).


Зарегистрируйтесь, чтобы оставить комментарий.