How to send Alt-key to application

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.
 
G

Guest

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.
 
G

Guest

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
 
G

Guest

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.
 
G

Guest

Thanks,

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

Edward
 
J

Jeff Johnson [MVP: VB]

'+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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top