QB64 Phoenix Edition
DAY 038: _MOUSEWHEEL - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: Official Links (https://qb64phoenix.com/forum/forumdisplay.php?fid=16)
+--- Forum: Learning Resources and Archives (https://qb64phoenix.com/forum/forumdisplay.php?fid=13)
+---- Forum: Keyword of the Day! (https://qb64phoenix.com/forum/forumdisplay.php?fid=49)
+---- Thread: DAY 038: _MOUSEWHEEL (/showthread.php?tid=1302)



DAY 038: _MOUSEWHEEL - Pete - 12-18-2022

Pretty simple...

SYNTAX scrollAmount% = _MOUSEWHEEL

Usage: Track the scrolling increments of the mouse wheel.

Example:
Code: (Select All)
DIM x AS INTEGER
DO
    _LIMIT 30
    WHILE _MOUSEINPUT
        x = x + _MOUSEWHEEL ' Must be placed inside WHILE/WEND loop.
    WEND
    lb = _MOUSEBUTTON(1) ' Left mouse button. Better placed outside of WHILE/WEND loop.
    IF lb THEN x = 0 ' reset mousewheel counter.
    LOCATE 1, 1: PRINT x; " ";
LOOP


One thing to keep in mind is unlike most of the other _MOUSE... keywords, _MOUSEWHEEL has to be placed between WHILE _MOUSEINPUT and WEND statements to be read, not after it like the _MOUSEBUTTON statements.

Note: _MOUSEMOVEX and _MOUSEMOVEY is another example of _MOUSE keywords which need to b placed between, not after, the WHILE/WEND _MOUSEINPUT loop.


Now if you only want to know the direction of the mouse wheel, use SGN() as in...

Code: (Select All)
DIM AS INTEGER x, sgnx
DO
    _LIMIT 30
    WHILE _MOUSEINPUT
        x = x + _MOUSEWHEEL
    WEND
    lb = _MOUSEBUTTON(1) ' Left mouse button.
    IF lb THEN x = 0 ' reset mousewheel counter.
    sgnx = SGN(x - oldx): oldx = x
    LOCATE 1, 1: PRINT x; " ";: IF sgnx THEN PRINT sgnx; "  ";: IF sgnx = -1 THEN PRINT "Up  "; ELSE PRINT "Down"; "   ";
LOOP

Pete