-
I am having a bit of trouble. Have a look at this code and look below to see my problem:
Code:
'What this code is supposed to do is
'simulate the mouse using the joypad
'or joystick.
Dim joypos As JOYINFO
joyGetPos 0, joypos
lblJoystickXPos.Caption = "X Position: " & joypos.wXpos
lblJoystickYPos.Caption = "Y Position: " & joypos.wYpos
lblJoystickZPos.Caption = "Z Position: " & joypos.wZpos
If (joypos.wButtons And JOY_BUTTON1) = JOY_BUTTON1 Then
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End If
If (joypos.wButtons And JOY_BUTTON2) = JOY_BUTTON2 Then
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
End If
'The mouse movement code goes
'here, but I won't include it
'because it takes up to much
'room.
This is repeated every millisecond by a timer. It has to be updated often so the positions can be read by the user. The 'If' statements are for when you push a button on the joystick. But the thing is, for every millisecond you hold down the joystick button, it clicks!
I need to find out a way to stop it from clicking every milliseconds, without changing the script too much.
-
Try this:
Code:
'What this code is supposed to do is
'simulate the mouse using the joypad
'or joystick.
Dim joypos As JOYINFO
joyGetPos 0, joypos
lblJoystickXPos.Caption = "X Position: " & joypos.wXpos
lblJoystickYPos.Caption = "Y Position: " & joypos.wYpos
lblJoystickZPos.Caption = "Z Position: " & joypos.wZpos
' Variables to store the last state of the buttons
Static lButtonHeld as Boolean
Static rButtonHeld as Boolean
' You have four cases:
' Button is pressed and was pressed last millisecond
' Button is pressed and was not pressed last millisecond
' Button is not pressed and was not pressed last millisecond
' Button is not pressed and was pressed last millisecond
'
' And the corresponding actions:
' User is holding; do nothing
' Execute a mouse_down
' User is doing nothing; do nothing
' Execute a mouse_up
If (joypos.wButtons And JOY_BUTTON1) = JOY_BUTTON1 Then
If not lButtonHeld then _
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
lButtonHeld = True
Else
If lButtonHeld then _
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
lButtonHeld = False
End If
' Do the same for the other button
- John
-