Results 1 to 4 of 4

Thread: Mouse Clicks

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Location
    East Anglia, England
    Posts
    73

    Post

    Hello,
    I was wondering how my program can tell when a mouse button has been clicked outside of it, i.e. in explorer.
    I've tryed subclassing but I've not had much luck.

    Many thanks,
    Desire

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Use the GetAsyncKeystate API within a Timer Control, ie.
    Code:
    Private Declare Function GetForegroundWindow Lib "user32" () As Long
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Const VK_LBUTTON = &H1
    Private Const VK_RBUTTON = &H2
    
    Private Sub Form_Load()
        Timer1.Interval = 100
    End Sub
    
    Private Sub Timer1_Timer()
        Dim sText As String
        sText = Space(255)
        sText = Left$(sText, GetWindowText(GetForegroundWindow, ByVal sText, 255))
        
        If GetAsyncKeyState(VK_LBUTTON) Then
            'Left Mouse Button Pressed...
            Debug.Print "Left Click in [" & sText & "]"
        ElseIf GetAsyncKeyState(VK_RBUTTON) Then
            'Right Mouse Button Pressed..
            Debug.Print "Right Click in [" & sText & "]"
        End If
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Certified AllExperts Expert

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Location
    East Anglia, England
    Posts
    73

    Post

    Thanks for the sample aaron it works great with the left and right mouse buttons but it doesn't recoginsed when my middle mouse button has been clicked. If you have any ideas about how to solve this then I would be most gratefull.

    Many thanks,
    Desire

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Do the same thing and include an extra IF statement for VK_MBUTTON, the Constant Value is:

    Private Const VK_MBUTTON = &H4

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Certified AllExperts Expert

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