_MOUSEINPUT problem
Posted: Thu Aug 20, 2015 5:07 pm
I am having trouble reading the mouse inputs. It seems that after there has been a mouse click, the mouse has to be read (_MOUSEINPUT) a number of times before it will know that there is no more input i.e. before it will go back to zero. This is most evident if the mouse is moved - it may have to be read 100 times before it resets to zero.
In the following test code, it works as long as the mouse is not moved, although sometimes requires 2 or 3 loops to reset. If the mouse is moved between clicks, it can require over 100 loops.
SCREEN 12
_FULLSCREEN
DO WHILE INKEY$ = "" ' <--- hit any key to exit
IF _MOUSEINPUT < 0 THEN
mi = _MOUSEINPUT
PRINT "Do your thing here. mi = ", mi, c
IF _MOUSEBUTTON(1) < 0 THEN PRINT "Left"
DO WHILE _MOUSEINPUT < 0 'mi < 0 ' <--- LET THE MOUSE "RECOVER" TO ZERO!!! Or it won't work if mouse moves
mi = _MOUSEINPUT
c = c + 1 ' <--- To prove it, count how many times it loops before going to zero
_DELAY 0.1 ' <-- Even with a delay, it still needs many loops, especially if mouse has been moved between clicks
LOOP
END IF
PRINT "mouse button up", c
c = 0: mi = 0
_DELAY .5 ' <--Slow the whole thing down so you can read it
LOOP
PRINT c, "exit"
Also, the first time through the IF statement, the input is always -1, even though the mouse has not been clicked.
Am I doing something wrong here?
In the following test code, it works as long as the mouse is not moved, although sometimes requires 2 or 3 loops to reset. If the mouse is moved between clicks, it can require over 100 loops.
SCREEN 12
_FULLSCREEN
DO WHILE INKEY$ = "" ' <--- hit any key to exit
IF _MOUSEINPUT < 0 THEN
mi = _MOUSEINPUT
PRINT "Do your thing here. mi = ", mi, c
IF _MOUSEBUTTON(1) < 0 THEN PRINT "Left"
DO WHILE _MOUSEINPUT < 0 'mi < 0 ' <--- LET THE MOUSE "RECOVER" TO ZERO!!! Or it won't work if mouse moves
mi = _MOUSEINPUT
c = c + 1 ' <--- To prove it, count how many times it loops before going to zero
_DELAY 0.1 ' <-- Even with a delay, it still needs many loops, especially if mouse has been moved between clicks
LOOP
END IF
PRINT "mouse button up", c
c = 0: mi = 0
_DELAY .5 ' <--Slow the whole thing down so you can read it
LOOP
PRINT c, "exit"
Also, the first time through the IF statement, the input is always -1, even though the mouse has not been clicked.
Am I doing something wrong here?