How to send Alt-key to application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

From mine application I start another win-app using Process.Start(). Normally, when using the keyboard I can press Alt-F to access the file menu. How can I access the menu from within the first app using Process.StandardInput? Or, how can I send the Alt-key to this app?
Thanks in advance.
 
You can use the Send or SendWait methods of the System.Windows.Forms.SendKeys class to send any key-combination to the active application. E.g. to send Alt+F you would use the code:

SendKeys.Send("+F");

Regards, Jakob.
 
Thanks,
but I cannot use SendKeys. I have a console app which starts a windows app with code like:
Process myProc = new Process();
myProc.StartInfo.FileName = @"notepad.exe";
myProc.StartInfo.UseShellExecute = false;
myProc.StartInfo.RedirectStandardInput = true;
myProc.Start();

When using SendKeys it's send to the console app. In this case I want notepad to receive the Alt-F.

Any suggestions?
Thanks.
Edward
 
SendKeys always sends the keys to the active application. You need to wait for notepad to be able to receive input. The following code seems to work. It waits 3 seconds for notepad to enter idle state:

Process myProc = new Process();
myProc.StartInfo.FileName = @"notepad.exe";
myProc.StartInfo.UseShellExecute = false;
myProc.StartInfo.RedirectStandardInput = true;
myProc.Start();
if (myProc.WaitForInputIdle(3000))
SendKeys.SendWait("%F");

'+F' does not seem to work so I may have misinformed you in my previous post. Use '%F' instead as in the code above.

Regards, Jakob.
 
Thanks,

The problem I had was getting the called application to the foreground. Works now.

Edward
 
'+F' does not seem to work so I may have misinformed you in my previous
post. Use '%F' instead as in the code above.

+ would mean Shift, % Alt, and ^ Ctrl.
 
This is totally unrelated to the Alt-key, but it IS related to the post Mr.
Johnson made. I am writing an app that is supposed to send Ctrl+S to
whatever app is in the foreground. Thanks.
 
Back
Top