views:

66

answers:

4

Hello everybody!

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?

A: 

Sendkeys.SendWait may solve your problem.

Yossarian
SendKeys can only send keystrokes to the active application, which is unfortunately not the case here.
ifroz
A: 

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

Marc Gravell
The console itself does not even exist as a window (Process.CreateNoWindow), so SendKeys is not applicable in this case.
ifroz
+1  A: 

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.

Hans Passant
There is no way to push some data to the buffer it reads, is there?
ifroz
No console window == no buffer.
Hans Passant
A: 

This isn't directly an answer to your question, but have you considered using MSMQ?

If your windowed application can receive those key-presses, it could pass that fact on to your console application using MSMQ. You may not have to actually pass the key-press, just the the fact that they were pressed.

I have found this techrepublic article helpful in getting the basics of MSMQ working.

Jonathan