09-02-2025, 02:51 AM
This type set up:
It really is just that simple. One variable to track the current button state. A second variable to record the old button state.
If the old state was UP and the new state is DOWN, it's a click.
IF the old state was DOWN and the new state is DOWN, it's not a click... It would be the button being held down and you could start counting it as a hold event.
IF the old state was UP and the new state is UP, then the mouse button is up and not being pressed.
If the old state was DOWN and the new state is UP, it means the user just released the mouse button. It's the end of a click or hold state and not the start of one.
Two variables, working together, and you can get all that info if you need it. In this case, all you're looking for is the simple CLICK result and that's only obtained when the new state is DOWN and the old state was UP previously.
Code: (Select All)
Do 'start of your do loop
While _MouseInput: Wend 'update the mouse buffer
MouseDown = _MouseButton(1) 'get the state of the mouse
Cls
Print "Mouse clicks:"; TotalClicks 'print the count so we can watch it only increase once per click
If MouseDown _AndAlso OldMouseUp Then 'the mouse was up, it's now down, we can count it as a click
TotalClicks = TotalClicks + 1
End If
OldMouseUp = _Negate MouseDown 'update the old button status so we can make certain it was up before counting the next click
_Limit 30
Loop Until _MouseButton(2) _OrElse _KeyHit
System
It really is just that simple. One variable to track the current button state. A second variable to record the old button state.
If the old state was UP and the new state is DOWN, it's a click.
IF the old state was DOWN and the new state is DOWN, it's not a click... It would be the button being held down and you could start counting it as a hold event.
IF the old state was UP and the new state is UP, then the mouse button is up and not being pressed.
If the old state was DOWN and the new state is UP, it means the user just released the mouse button. It's the end of a click or hold state and not the start of one.
Two variables, working together, and you can get all that info if you need it. In this case, all you're looking for is the simple CLICK result and that's only obtained when the new state is DOWN and the old state was UP previously.


