Programmatic Alt+Tab

  • Thread starter Thread starter Adam J. Schaff
  • Start date Start date
A

Adam J. Schaff

How can I issue an Alt+Tab command from within VB.NET code?

Specifically, I am trying to swap to the next application in the Alt+Tab
order in a way that is reversible with a single Alt+Tab to get back to my
application. That sounds redundant, but what I've found is that if I
minimize my app, it goes to the very end of the Alt+Tab list instead of
being the next in line.


Related Ramblings:
Oddly enough, in VB6, I had this behavior. Setting frm.WindowState =
vbMinimize would minimize my app but still keep it next in line for Alt+Tab.
The same (equivalent) code in VB.NET places it at the end of the Alt+Tab
list, which is no good for what I'm after.

Now I checked, and if I minimize my app by hand, it also goes to the back of
the order, so I think that the VB.NET WindowState=Minimize command more
correctly mimics user behavior. Nevertheless, it isn't what I'm after. So
I've decided that it's ok if my app doesn't minimize; it just needs to give
focus to the previous window in a way that allows the user to Alt+Tab back
to it with a single Alt+Tab.

Any help is appreciated.
-AJ
 
When you want to activate the other application, try using the following

--------------------------
Microsoft.VisualBasic.AppActivate("Untitled - Notepad")
-----------------------

This should activate the application. Change "Untitled-Notepad" to whatever
the text in the title bar of the application is (You can also use the
Program ID). It should also leave your application next in the Alt+Tab
order.

HTH,

Trev
 
Hmm, perhaps I should have been more specific. I don't know what application
I want to move to, so I can't use its name. I simply want to switch to
whichever application is next in the tab order. So what I want is behavior
exactly like pressing Alt+Tab once.
 
Try the following:

System.Windows.Forms.SendKeys.Send("%{TAB}")

This sends the ALT+Tab combination. I've tried this on WindowsXP and it seem
to work the way it should.

Hope this helps,

Trev.
 
Back
Top