如何偵察滑鼠是否按下了開始鍵?
如何偵察滑鼠是否按下了開始鍵呢?首先要知道開始鍵的hWnd,然後判斷滑鼠的狀態:
Option Explicit
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Type POINTAPI
x As Long
y As Long
End Type
Private Const GW_CHILD = 5
Dim MousePoint As POINTAPI
Dim GethWnd As Long
Dim TrayhWnd As Long, StarthWnd As Long
Private Sub Form_Activate()
Do
DoEvents
GetCursorPos MousePoint
GethWnd = WindowFromPoint(MousePoint.x, MousePoint.y)
If GethWnd <> StarthWnd Then
Me.Caption = "滑鼠沒有按下開始鍵"
ElseIf GethWnd = StarthWnd And GetAsyncKeyState(&H1) Then
Me.Caption = "滑鼠左鍵按下了開始鍵"
ElseIf GethWnd = StarthWnd And GetAsyncKeyState(&H2) Then
Me.Caption = "滑鼠右鍵按下了開始鍵"
End If
Loop
End Sub
Private Sub Form_Load()
TrayhWnd = FindWindow("Shell_TrayWnd", vbNullString)
StarthWnd = GetWindow(TrayhWnd, GW_CHILD)
End Sub