PDA

Click to See Complete Forum and Search --> : How to detect when mouse is down


Mass
Jun 20th, 2000, 08:42 PM
Hi

Hi

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

Jun 22nd, 2000, 05:29 PM
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

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,

Mass
Jun 23rd, 2000, 05:12 PM
Grate It works fine but could you also tell me how to detect other events like dblclicks?

Thanks a lot