Results 1 to 3 of 3

Thread: How to detect when mouse is down

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    175

    Talking

    Hi

    Hi

    I need to know when a Mouse button clicks or has been pushed Down on other Applications


    Mass

  2. #2
    Guest
    Use the GetASyncKeyState to trap when the mouse has been pressed/is down.


    Example:
    Add a timer called Timer1 to a form set its interval to 100.

    Insert the followinf code
    Code:
    Option Explicit
    Private Const VK_LBUTTON As Long = &H1  '//Left mouse button
    Private Const VK_RBUTTON As Long = &H2  '//Right mouse button
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    
    Private Sub Timer1_Timer()
        Dim lRet As Long
        lRet = GetAsyncKeyState(VK_LBUTTON)
        If lRet <> 0 Then
            Debug.Print "Left Mouse is " & TranslateValue(lRet)
        End If
        lRet = GetAsyncKeyState(VK_RBUTTON)
        If lRet <> 0 Then
            Debug.Print "Right Mouse is " & TranslateValue(lRet)
        End If
    End Sub
    
    Private Function TranslateValue(ByVal lValue As Long) As String
        Select Case lValue
            Case 0      'Nothing, 'key' hasn't been pressed
            Case 1      'Huh?
                TranslateValue = "Unkown state"
            Case -32767 'Click, first recording of 'key'press
                TranslateValue = "Pressed"
            Case -32768 ''Key' is down
                TranslateValue = "Down"
            Case Else   'Another, hmmm whats this
                TranslateValue = "Unkown state"
        End Select
    End Function
    Hope it helps,

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    175

    Wink

    Grate It works fine but could you also tell me how to detect other events like dblclicks?

    Thanks a lot
    Mass

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width