Determine when a user's left/right mouse button is pressed or released at any time anywhere!
Determine when a user's left/right mouse button is pressed or released at any time anywhere!
API Declarations
Public Declare Function SystemParametersInfo Lib "user32.dll" Alias "SystemParametersInfoA" (ByVal Action As Long, ByVal Param As Long, Param As Any, ByVal WinIni As Long) As Long
Public Const SPI_SCREENSAVERRUNNING = 97
Public Enum MouseButtons
LeftButton = 1
RightButton = 2
End Enum
Rate Determine when a user's left/right mouse button is pressed or released at any time anywhere!
(2(2 Vote))
'Put a timer on your form and set it to 1 interval then copy and paste the code.
Private Sub Form_Load()
Dim pvParam As Boolean
Call SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, pvParam, 0)
End Sub
'Set the timer to 1 interval
Private Sub Timer1_Timer()
Dim KeyResult As Long, X As Integer
Static Initialized As Boolean, MouseDown As Boolean, RightButton As Boolean
KeyResult = GetAsyncKeyState(MouseButtons.LeftButton)
If CBool(KeyResult) Then
If Not Initialized Then
Initialized = True
Else
If Not MouseDown Then
Debug.Print "Left Mouse Down"
RightButton = False
MouseDown = True
End If
End If
Else
KeyResult = GetAsyncKeyState(MouseButtons.RightButton)
If Not CBool(KeyResult) Then
If MouseDown Then
If Not RightButton Then
Debug.Print "Left Mouse Up"
Else
Debug.Print "Right Mouse Up"
End If
End If
MouseDown = False
End If
End If
KeyResult = GetAsyncKeyState(MouseButtons.RightButton)
If CBool(KeyResult) Then
If Not MouseDown Then
Debug.Print "Right Mouse Down"
RightButton = True
MouseDown = True
End If
Else
KeyResult = GetAsyncKeyState(MouseButtons.LeftButton)
If Not CBool(KeyResult) Then
If MouseDown Then
If Not RightButton Then
Debug.Print "Left Mouse Up"
Else
Debug.Print "Right Mouse Up"
End If
End If
MouseDown = False
End If
End If
DoEvents
End Sub
Determine when a user's left/right mouse button is pressed or released at any time anywhere! Comments
No comments yet — be the first to post one!
Post a Comment