i am trying to figure out how to make a program to detect if a left or right mouse button has been pressed using a VB6 application that is hidden. does anyone know if this is even possible using vb6? im new at programming so im not sure where to even start. thanks guys
Last edited by RhythmMike; Apr 13th, 2004 at 03:00 PM.
thats exactly what i have been looking for! thanks soo much! now im wondering... is there anyway that it will record only when you press the middle mouse button?
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Dim file_contents As String
Private Sub Timer1_Timer()
Dim Ret As Integer
Ret = GetAsyncKeyState(1) 'vbKeyLButton = 1
If Ret < 1 Then
Text1.Text = Text1.Text + 1
End If
End Sub
i added a text box to show every time it is clicked but for some reason the text box just keep going up whether i click or not.. i then changed it to If Ret = 1 Then and with that you have to click the mouse a few times before it adds one to the text. anyone know whats goin on?
Its the Timer's Interval. You need to try and get it to the right one. It has to be close to the human reaction time for clicking a mouse. You just need to experiment with it, changing the Timer's interval property to lower values.
EDIT:
And you should keep it
VB Code:
If Ret < 1 Then
If it is < 1 it means the mouse is DOWN. If it is 1, it means the mouse is UP...
i dont understand what you mean.. using that code i was thinking that everytime you click it would add +1.. using the timer and when Ret < 1 it only adds +1 once the timer runs down
Once (1 time) a second, the program checks if the Mouse is DOWN (Ret < 1). If it IS down, it writes to the file (your program adds to a textbox). If it ISN'T down (Ret = 1) then it does nothing. The timer will continue to execute that code Once (1 time) per second, until the program is closed..
EDIT:
Also, the Mouse MUST be down at the exact time the timer executes that code, which is why you need to put it to a smaller value than Once a second.
ok i understand it now.. thank you! now im wondering... is there a way to make the timer less than 1? i have it so that when you hold down the button it adds +1 each time the timer counts down from 1, but i want it a faster.. i know i didnt explain it very well