- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
> 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page