Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am writing a windowed .NET app in C#, which runs a third party console application via the Process class, as hidden as possible (CreateNoWindow, RedirectStandardOutput, etc.).

I've redirected it's StandardInput, so I can write whatever string I want, but not function keys or other type of special keys, as they don't have a character representation. As for me, I have to send keys F1 to F4 to the console app. The solutions I've found are for windowed app (PostMessage, SendMessage).

How can I do this for my console application?

Is there anything to do with the Handle of the Process?

like image 462
ifroz Avatar asked Jun 25 '10 10:06

ifroz


1 Answers

You can't. Function keys cannot work with stdin, an app has to call ReadConsoleInput() to be able to detect them. That no longer works when you start the process without a console window.

like image 103
Hans Passant Avatar answered Oct 18 '22 01:10

Hans Passant