How to send keypress function (F1..F12) to console application in .NET.

I am writing a .NET windowed application in C # that launches a third-party console application through the Process class, as hidden as possible (CreateNoWindow, RedirectStandardOutput, etc.).

I redirected it to StandardInput, so I can write any line that I want, but not function keys or other special keys, since they have no character representation. For me, I have to send the F1 keys to F4 to the console application. The solutions I found are for a windowed application (PostMessage, SendMessage).

How to do this for a console application?

Is there anything related to process processing?

+6
c # process keypress handle
source share
4 answers

You can not. Function keys cannot work with stdin, the application must call ReadConsoleInput () in order to be able to detect them. This no longer works when you start the process without a console window.

+1
source share

Sendkeys.SendWait may solve your problem.

0
source share

Does SendKeys work ( "{F1}" )? (the console should be active, though).

0
source share

This is not a direct answer to your question, but do you think you are using MSMQ?

If your windowed application can receive these keystrokes, it can pass this fact on to your console application using MSMQ. You may not have to actually transmit the keystroke, just the fact that they were pressed.

I found this technical article useful for getting the basics of MSMQ.

0
source share

All Articles