By
using calls to the keybd_event API, an application can perform tasks as though the user had clicked on the start menu button or right-clicked
the taskbar.
This demo shows how to launch Explorer, Find Files, and the Run
Dialog, open the Start Menu, Minimize all windows, and launch Windows Help, all using the keybd_event API. |
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
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 VK_LWIN = &H5B
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_APPS = &H5D
Private Sub Command1_Click(Index As Integer)
Dim VK_ACTION As Long
Select Case Index
Case 0: '&H45 is the hex character code
'for the letter 'E' (ascii 69)
VK_ACTION = &H45
Case 1: '&H46 is the hex character code
'for the letter 'F' (ascii 70)
VK_ACTION = &H46
Case 2: '&H4D is the hex character code
'for the letter 'M' (ascii 77)
VK_ACTION = &H4D
Case 3: '&H52 is the hex character code
'for the letter 'R' (ascii 82)
VK_ACTION = &H52
Case 4: '&H5B is the hex character code
'for the start menu button
VK_ACTION = &H5B
Case 5: '&H5E is the hex character code
'for the caret chr (ascii 94)
VK_ACTION = &H5E
Case 6: '&H70 is the hex character code
'for the caret chr (ascii 112)
VK_ACTION = &H70
End Select
Call keybd_event(VK_LWIN, 0, 0, 0)
Call keybd_event(VK_ACTION, 0, 0, 0)
Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
End Sub |