From Steve:
The best practice is: WHILE _MOUSEINPUT: WEND. It truly is the equivalent to _KEYCLEAR, for the mouse.
From Luke:
Any code with a wild WHILE _MOUSEINPUT: WEND will miss clicks. It works as a _KEYCLEAR for the mouse, certainly, but you don't want to have it in a handling loop.
Two of our Great Masters at complete loggerheads (and Fellippe's contributions were rather over my head).
Not in disagreement. Luke was saying that stray WHILE _MOUSEINPUT: WEND routines will cause you to miss events, and he’s right. You only need the main mousepolling event ONCE, in your main loop. As I said, think of it as a _KEYCLEAR for your mouse:
DO
_DELAY 1
k = _KEYHIT ‘get single byte from the keyboard buffer
_KEYCLEAR ‘this keyclear will eliminate all the extra buffer events
PRINT k
LOOP
With the above, you might bang out “ASDFG” on the keyboard and only print out “A” to the screen. You put extra events into the buffer, but then used _KEYCLEAR to erase them before handling them once each second.
A stray/unneeded _KEYCLEAR causes keyboard input to be missed. Unnecessary uses of WHILE _MOUSEINPUT: WEND do the same for the mouse.
I’d guess if you’re you’re getting unwanted events, it’s from simply detecting “mouse down” events instead of “mouse click” events.
A mouse down checker is as simple as:
IF _MOUSEBUTTON(1) THEN....
A mouse click checker needs to be something a little more, like:
CONST Up = 0, Down = -1
IF OldState = Up THEN ‘if the mouse was up last pass
IF _MOUSEBUTTON(1) = Down THEN ‘and it’s down now — We went from up to down
... do click stuff
END IF
END IF
OldState = _MOUSEBUTTON(1) ‘store the state of this pass to compare next pass
******
You don’t want to just check to see that the mouse was down for your needs. After all, holding it down for 10 seconds shouldn’t generate 1000 mouse clicks... You want it to at least be counted as an, “It WAS up, but now it’s down” type event.
(And If you’re adding “hold events”, you basically need to check, “It WAS up, then down, then released back up” for a click; “Up, down, staying down” for a hold event.)
Feel free to share your actual code, and I’ll be more than happy to look over it. ;)