Results 1 to 2 of 2

Thread: mouse click

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    didn't decide yet
    Posts
    566

    mouse click

    how can i detect left and right mouse click not only at the form but everywhere from desktop to taskbar to any open application to form of my app

    thnks
    Come and get our ISDN CallerID http://www.3wm.biz

  2. #2
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    If you are using Windows NT / XP / 2000 you can install a system wide WH_MOUSE_LL hook or if the code has to work in all systems install a WH_JOURNALRECORD hook and filter out the mouse messages only.

    Demo code using EventVB.dll release H which must be downloaded and registered on your machine:

    WH_MOUSE_LL code:
    VB Code:
    1. Option Explicit
    2.  
    3. Dim WithEvents vbLink As EventVB.APIFunctions
    4. Dim WithEvents vbHook As EventVB.ApiSystemHook
    5.  
    6. Private Sub Form_Load()
    7.  
    8. Set vbLink = New EventVB.APIFunctions
    9.  
    10. Set vbHook = vbLink.System.Hooks
    11. vbHook.StartHook WH_MOUSE_LL, HOOK_GLOBAL
    12.  
    13.  
    14. End Sub
    15.  
    16. Private Sub vbHook_MouseButtonDown(ByVal Button As Integer, ByVal Location As EventVB.APIPoint, ByVal TargetWindow As EventVB.ApiWindow, Cancel As Boolean)
    17.  
    18. Debug.Print "Mouse button down at " & Location.x & "," & Location.y
    19. '\\ To discard this message, set Cancel = True
    20.  
    21. End Sub
    22.  
    23. Private Sub vbHook_MouseButtonUp(ByVal Button As Integer, ByVal Location As EventVB.APIPoint, ByVal TargetWindow As EventVB.ApiWindow, Cancel As Boolean)
    24.  
    25. Debug.Print "Mouse button up at " & Location.x & "," & Location.y
    26. '\\ To discard this message, set Cancel = True
    27.  
    28. End Sub
    29.  
    30. Private Sub vbHook_MouseMove(ByVal Location As EventVB.APIPoint, ByVal TargetWindow As EventVB.ApiWindow, Cancel As Boolean)
    31.  
    32. Debug.Print "Mouse move to " & Location.x & "," & Location.y
    33. '\\ To discard this message, set Cancel = True
    34.  
    35. End Sub
    36.  
    37. Private Sub vbHook_MouseWheelMove(ByVal Rotation As Integer, ByVal Location As EventVB.APIPoint, ByVal TargetWindow As EventVB.ApiWindow, Cancel As Boolean)
    38.  
    39. Debug.Print "Mouse wheel moved by " & Rotation & " at " & Location.x & "," & Location.y
    40. '\\ To discard this message, set Cancel = True
    41.  
    42. End Sub

    WH_JOURNALRECORD code:
    VB Code:
    1. Option Explicit
    2.  
    3. Dim WithEvents vbLink As EventVB.APIFunctions
    4. Dim WithEvents vbHook As EventVB.ApiSystemHook
    5.  
    6. Private Sub Form_Load()
    7.  
    8. Set vbLink = New EventVB.APIFunctions
    9.  
    10. Set vbHook = vbLink.System.Hooks
    11. vbHook.StartHook WH_JOURNALRECORD, HOOK_GLOBAL
    12.  
    13.  
    14. End Sub
    15.  
    16. Private Sub vbHook_JournalMouseMessage(ByVal msg As EventVB.WindowMessages, ByVal x As Long, ByVal y As Long, ByVal time As Long, ByVal TargetWindow As EventVB.ApiWindow)
    17.  
    18. If msg = WM_LBUTTONDOWN Or msg = WM_MBUTTONDOWN Or msg = WM_RBUTTONDOWN Then
    19.     Debug.Print "Mouse button down at " & x & "," & y
    20. ElseIf msg = WM_LBUTTONUP Or msg = WM_MBUTTONUP Or msg = WM_RBUTTONUP Then
    21.     Debug.Print "Mouse button up at " & x & "," & y
    22. End If
    23.  
    24. End Sub

    Hope this helps,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

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