Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mouse Help Needed
#21
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)




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:
Reply


Messages In This Thread
Mouse Help Needed - by SierraKen - 05-02-2022, 01:30 AM
RE: Mouse Help Needed - by bplus - 05-02-2022, 01:56 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 02:03 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 02:11 AM
RE: Mouse Help Needed - by bplus - 05-02-2022, 02:48 AM
RE: Mouse Help Needed - by bplus - 05-02-2022, 03:54 AM
RE: Mouse Help Needed - by bplus - 05-02-2022, 04:03 AM
RE: Mouse Help Needed - by bplus - 05-02-2022, 04:22 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 04:26 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 04:25 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 04:30 AM
RE: Mouse Help Needed - by bplus - 05-02-2022, 04:32 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 04:33 AM
RE: Mouse Help Needed - by bplus - 05-02-2022, 04:37 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 04:52 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 05:09 AM
RE: Mouse Help Needed - by dcromley - 05-02-2022, 04:51 PM
RE: Mouse Help Needed - by bplus - 05-02-2022, 05:10 PM
RE: Mouse Help Needed - by OldMoses - 05-02-2022, 06:17 PM
RE: Mouse Help Needed - by bplus - 05-02-2022, 06:58 PM
RE: Mouse Help Needed - by OldMoses - 05-02-2022, 11:53 PM
RE: Mouse Help Needed - by SierraKen - 05-03-2022, 11:26 PM
RE: Mouse Help Needed - by SierraKen - 05-03-2022, 11:34 PM
RE: Mouse Help Needed - by OldMoses - 05-04-2022, 04:37 PM
RE: Mouse Help Needed - by bplus - 05-04-2022, 04:43 PM
RE: Mouse Help Needed - by OldMoses - 05-04-2022, 05:04 PM
RE: Mouse Help Needed - by bplus - 05-04-2022, 05:12 PM
RE: Mouse Help Needed - by OldMoses - 05-05-2022, 12:25 AM



Users browsing this thread: 2 Guest(s)