VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Determine when a user's left/right mouse button is pressed or released at any time anywhere!

by Cache (3 Submissions)
Category: Windows System Services
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 25th February 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

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!



'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

Download this snippet    Add to My Saved Code

Determine when a user's left/right mouse button is pressed or released at any time anywhere! Comments

No comments have been posted about Determine when a user's left/right mouse button is pressed or released at any time anywhere!. Why not be the first to post a comment about Determine when a user's left/right mouse button is pressed or released at any time anywhere!.

Post your comment

Subject:
Message:
0/1000 characters