Link to home
Create AccountLog in
Avatar of glwhatrup
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
Avatar of vinnyd79
vinnyd79

vinnyd79 you are fast;)
ASKER CERTIFIED SOLUTION
Avatar of vinnyd79
vinnyd79

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
=============================================
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
**********************************************************************

Avatar of glwhatrup

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