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
Printable View
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
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
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
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