glwhatrup
asked on
"Alt" & "Tab" keys in VB
Hi guys,
I have the following code which is the equivalent of pressing "windows" & "F" to bring up the search bar. (courtesy of mvidas - thanks!)
If I have this in a live powerpoint slideshow, it brings the search bar up behind the active slideshow, so I would like the modify the code to add "Alt"&"Tab" to bring it to the front.
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Sub OpenSearchWindow()
keybd_event &H5B, 0, 0, 0 'windows key
keybd_event &H46, 0, 0, 0 'F
keybd_event &H5B, 0, &H2, 0 'keys up
End Sub
Obviously it would be "keybd_event...", but I'm not sure what the codes for the rest of the keyboard are.
Any help greatly appreciated
Thanks
G
I have the following code which is the equivalent of pressing "windows" & "F" to bring up the search bar. (courtesy of mvidas - thanks!)
If I have this in a live powerpoint slideshow, it brings the search bar up behind the active slideshow, so I would like the modify the code to add "Alt"&"Tab" to bring it to the front.
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Sub OpenSearchWindow()
keybd_event &H5B, 0, 0, 0 'windows key
keybd_event &H46, 0, 0, 0 'F
keybd_event &H5B, 0, &H2, 0 'keys up
End Sub
Obviously it would be "keybd_event...", but I'm not sure what the codes for the rest of the keyboard are.
Any help greatly appreciated
Thanks
G
vinnyd79 you are fast;)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
========================== ========== =========
This is the 'MapVirtualKey' method to send an "Alt Tab" combination :
========================== ========== =========
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Const VK_TAB = &H9 'Tab
Const VK_MENU = &H12 'ALT
************************** ********** ********** ********** ********** ****
keybd_event VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0 ' 0=press alt
keybd_event VK_TAB, MapVirtualKey(VK_TAB, 0), 0, 0
keybd_event VK_TAB, MapVirtualKey(VK_TAB, 0), 2, 0
keybd_event VK_MENU, MapVirtualKey(VK_MENU, 0), 2, 0 ' 2=release alt
************************** ********** ********** ********** ********** ****
This is the 'MapVirtualKey' method to send an "Alt Tab" combination :
==========================
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Const VK_TAB = &H9 'Tab
Const VK_MENU = &H12 'ALT
**************************
keybd_event VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0 ' 0=press alt
keybd_event VK_TAB, MapVirtualKey(VK_TAB, 0), 0, 0
keybd_event VK_TAB, MapVirtualKey(VK_TAB, 0), 2, 0
keybd_event VK_MENU, MapVirtualKey(VK_MENU, 0), 2, 0 ' 2=release alt
**************************
ASKER
Dear All,
Thanks for all your quick replies and useful links. I accepted vinnyd79's answer, as it just added "alt"&"tab" to the code I already had - which was all I was after.
vb_elmars solution is a valid one as well though - so thankyou to all!
Regards
G
Thanks for all your quick replies and useful links. I accepted vinnyd79's answer, as it just added "alt"&"tab" to the code I already had - which was all I was after.
vb_elmars solution is a valid one as well though - so thankyou to all!
Regards
G
alt - &H12
tab - &H9
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp