Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17060 Discussions

key pressing emulation with CreateProces

Intel_C_Intel
Employee
502 Views
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
0 Kudos
3 Replies
Jugoslav_Dujic
Valued Contributor II
502 Views
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
0 Kudos
Intel_C_Intel
Employee
502 Views
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
0 Kudos
Jugoslav_Dujic
Valued Contributor II
502 Views
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).
0 Kudos
Reply