Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2004

Tip: Looking for answers? Try searching our database.

How to send Alt-key to application

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Edward - 28 Jun 2004 09:44 GMT
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.
Jakob Christensen - 28 Jun 2004 10:10 GMT
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.

> 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.
Edward - 28 Jun 2004 10:22 GMT
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

> 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:
>
[quoted text clipped - 4 lines]
> > 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.
Jakob Christensen - 28 Jun 2004 12:05 GMT
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,
> but I cannot use SendKeys. I have a console app which starts a windows app with code like:
[quoted text clipped - 18 lines]
> > > 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.
Edward - 28 Jun 2004 12:27 GMT
Thanks,

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

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:
>
[quoted text clipped - 32 lines]
> > > > 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.
Jeff Johnson [MVP: VB] - 28 Jun 2004 17:06 GMT
> '+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.
psduckie - 28 Dec 2004 21:51 GMT
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.

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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.