Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleSimulate Alt-Tab in Visual Basic 6
DescriptionThis example shows how to simulate Alt-Tab in Visual Basic 6. That moves focus to the next application running.
KeywordsAlt-Tab, simulate, Visual Basic 6, keyboard, keybd_event
CategoriesMiscellany, Software Engineering, API
 
The following code uses the keybd_eventj API function to simulate pressing the Alt key, pressing the Tab key, and releasing the Alt key.
 
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As _
    Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal _
    dwExtraInfo As Long)
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_ALT = &H12
Private Const VK_TAB = &H9

' Grab all of the text in the WebBrowser control.
Private Sub Command1_Click()
    ' Press Alt.
    keybd_event VK_ALT, 0, 0, 0
    DoEvents

    ' Press Tab.
    keybd_event VK_TAB, 1, 0, 0
    DoEvents

    ' Release Alt.
    keybd_event VK_ALT, 0, KEYEVENTF_KEYUP, 0
    DoEvents
End Sub
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated