Of course, if one is only avoiding subs, the code would work just the same cut and pasted in the appropriate place, then substitute the mousebutton ID for 'var'. The only real point of the sub is to reduce typing redundancy, and the fact that QB64 is fast enough that the nested loop will probably work faster than any delay that would accommodate human fingers.
I typically use Clear_MB # in anything that uses Steve's MBS function. My typical main program input loop looks like the following. I find it easy peasy, and I should probably put it in an include library. It works like a charm and I never have "click through" problems.
(Note: the Clear_MB number is the mouse button number, not necessarily what MBS returns)
I typically use Clear_MB # in anything that uses Steve's MBS function. My typical main program input loop looks like the following. I find it easy peasy, and I should probably put it in an include library. It works like a charm and I never have "click through" problems.
(Note: the Clear_MB number is the mouse button number, not necessarily what MBS returns)
Code: (Select All)
DO 'main program display loop
in% = 0
DO 'input loop
ky$ = INKEY$
ms% = MBS
IF ms% AND 1 THEN
Clear_MB 1
'Do left mouse initiated stuff
in% = -1
END IF
IF ms% AND 2 THEN
Clear_MB 2
'Do right mouse initiated stuff
in% = -1
END IF
IF ms% AND 4 THEN
Clear_MB 3
'Do center mouse initiated stuff
in% = -1
END IF
'etc.
'etc
'do inkey stuff, blank the ky$, then set in% = -1
'_LIMIT as necessary
LOOP UNTIL in%
'do general display update stuff
'_DISPLAY if required
LOOP UNTIL done 'whatever done entails
SUB Clear_MB (var AS INTEGER)
DO UNTIL NOT _MOUSEBUTTON(var)
WHILE _MOUSEINPUT: WEND
LOOP
END SUB 'Clear_MB
FUNCTION MBS% 'Mouse Button Status Author: Steve McNeill
STATIC StartTimer AS _FLOAT
STATIC ButtonDown AS INTEGER
STATIC ClickCount AS INTEGER
CONST ClickLimit## = 0.2 'Less than 1/4th of a second to down, up a key to count as a CLICK.
' Down longer counts as a HOLD event.
SHARED Mouse_StartX, Mouse_StartY, Mouse_EndX, Mouse_EndY
WHILE _MOUSEINPUT 'Remark out this block, if mouse main input/clear is going to be handled manually in main program.
SELECT CASE SGN(_MOUSEWHEEL)
CASE 1: tempMBS = tempMBS OR 512
CASE -1: tempMBS = tempMBS OR 1024
END SELECT
WEND
IF _MOUSEBUTTON(1) THEN tempMBS = tempMBS OR 1
IF _MOUSEBUTTON(2) THEN tempMBS = tempMBS OR 2
IF _MOUSEBUTTON(3) THEN tempMBS = tempMBS OR 4
IF StartTimer = 0 THEN
IF _MOUSEBUTTON(1) THEN 'If a button is pressed, start the timer to see what it does (click or hold)
ButtonDown = 1: StartTimer = TIMER(0.01)
Mouse_StartX = _MOUSEX: Mouse_StartY = _MOUSEY
ELSEIF _MOUSEBUTTON(2) THEN
ButtonDown = 2: StartTimer = TIMER(0.01)
Mouse_StartX = _MOUSEX: Mouse_StartY = _MOUSEY
ELSEIF _MOUSEBUTTON(3) THEN
ButtonDown = 3: StartTimer = TIMER(0.01)
Mouse_StartX = _MOUSEX: Mouse_StartY = _MOUSEY
END IF
ELSE
BD = ButtonDown MOD 3
IF BD = 0 THEN BD = 3
IF TIMER(0.01) - StartTimer <= ClickLimit THEN 'Button was down, then up, within time limit. It's a click
IF _MOUSEBUTTON(BD) = 0 THEN tempMBS = 4 * 2 ^ ButtonDown: ButtonDown = 0: StartTimer = 0
ELSE
IF _MOUSEBUTTON(BD) = 0 THEN 'hold event has now ended
tempMBS = 0: ButtonDown = 0: StartTimer = 0
Mouse_EndX = _MOUSEX: Mouse_EndY = _MOUSEY
ELSE 'We've now started the hold event
tempMBS = tempMBS OR 32 * 2 ^ ButtonDown
END IF
END IF
END IF
MBS% = tempMBS
END FUNCTION 'MBS%
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
sha_na_na_na_na_na_na_na_na_na: