MOUSEWHEEL: Difference between revisions
Jump to navigation
Jump to search
Example by Ted Weissgerber
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
No edit summary |
No edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 11: | Line 11: | ||
* After an event has been read, the value resets to 0 automatically so cumulative position values must be added. | * After an event has been read, the value resets to 0 automatically so cumulative position values must be added. | ||
* If no movement on the wheel has occurred since the last [[_MOUSEINPUT]] read, [[_MOUSEWHEEL]] returns 0. | * If no movement on the wheel has occurred since the last [[_MOUSEINPUT]] read, [[_MOUSEWHEEL]] returns 0. | ||
{{PageAvailability}} | {{PageAvailability}} | ||
<!-- QB64 = a version or none, QBPE = a version or all, Platforms = yes or no --> | |||
<gallery widths="48px" heights="48px" mode="nolines"> | <gallery widths="48px" heights="48px" mode="nolines"> | ||
File:Qb64.png|'''v0.851''' | File:Qb64.png|'''v0.851''' | ||
Line 21: | Line 21: | ||
File:Win.png|'''yes''' | File:Win.png|'''yes''' | ||
File:Lnx.png|'''yes''' | File:Lnx.png|'''yes''' | ||
File:Osx.png|''' | File:Osx.png|'''yes''' | ||
</gallery> | </gallery> | ||
<!-- additional availability notes go below here --> | |||
* Available for ''macOS'' since '''QB64-PE v3.13.0''' | |||
{{PageExamples}} | {{PageExamples}} | ||
; Example 1: Reading the cumulative mouse wheel "clicks". | |||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|DO}} | |||
DO WHILE {{Cl|_MOUSEINPUT}} | {{Cl|_LIMIT}} {{Text|50|#F580B1}} | ||
{{Cl|DO...LOOP|DO WHILE}} {{Cl|_MOUSEINPUT}} | |||
Scroll = Scroll + {{Cl|_MOUSEWHEEL}} | |||
LOOP | {{Cl|LOCATE}} {{Text|10|#F580B1}}, {{Text|20|#F580B1}}: {{Cl|PRINT}} Scroll | ||
{{Cl|LOOP}} | |||
{{Cl|DO...LOOP|LOOP UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}({{Text|13|#F580B1}}) {{Text|<nowiki>' press Enter to quit</nowiki>|#919191}} | |||
{{CodeEnd}} | {{CodeEnd}} | ||
---- | |||
; Example 2: A simple text scrolling routine using the mouse wheel value to read a text array. | |||
: You will need a text file that is large enough for this example.</center> | |||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|DIM}} Array$(100) | {{Cl|DIM}} Array$({{Text|100|#F580B1}}) | ||
{{Cl|LINE INPUT}} "Enter a file name with 100 or more lines of text: ", file$ | {{Cl|LINE INPUT}} {{Text|<nowiki>"Enter a file name with 100 or more lines of text: "</nowiki>|#FFB100}}, file$ | ||
{{Cl|OPEN}} file$ {{Cl| | {{Cl|OPEN}} file$ {{Cl|OPEN#File_Access_Modes|FOR}} {{Cl|OPEN#File_Access_Modes|INPUT}} {{Cl|OPEN|AS}} #1 | ||
{{Cl|DO...LOOP|DO}} {{Cl| | {{Cl|DO...LOOP|DO UNTIL}} {{Cl|EOF}}({{Text|1|#F580B1}}) | ||
inputcount = inputcount + {{Text|1|#F580B1}} | |||
{{Cl|LINE INPUT (file statement)|LINE INPUT}} #1, Array$(inputcount) | |||
{{Cl|IF}} inputcount = {{Text|100|#F580B1}} {{Cl|THEN}} {{Cl|EXIT DO}} | |||
{{Cl|LOOP}} | {{Cl|LOOP}} | ||
{{Cl | {{Cl|FOR}} n = {{Text|1|#F580B1}} {{Cl|TO}} {{Text|21|#F580B1}}: {{Cl|PRINT}} Array$(n): {{Cl|NEXT}} | ||
{{Cl|CLOSE}} #1 | {{Cl|CLOSE}} #1 | ||
DO | {{Cl|DO}} | ||
{{Cl|DO...LOOP|DO WHILE}} {{Cl|_MOUSEINPUT}} | |||
{{Cl|IF}} row >= {{Text|0|#F580B1}} {{Cl|THEN}} row = row + {{Cl|_MOUSEWHEEL}} {{Cl|ELSE}} row = {{Text|0|#F580B1}} {{Text|<nowiki>'prevent under scrolling</nowiki>|#919191}} | |||
{{Cl|IF}} row > inputcount - {{Text|20|#F580B1}} {{Cl|THEN}} row = inputcount - {{Text|20|#F580B1}} {{Text|<nowiki>'prevent over scrolling</nowiki>|#919191}} | |||
{{Cl|IF}} prevrow <> row {{Cl|THEN}} {{Text|<nowiki>'look for a change in row value</nowiki>|#919191}} | |||
{{Cl|IF}} row > {{Text|0|#F580B1}} {{Cl|AND (boolean)|AND}} row <= inputcount - {{Text|20|#F580B1}} {{Cl|THEN}} | |||
{{Cl|CLS}}: {{Cl|LOCATE}} {{Text|2|#F580B1}}, {{Text|1|#F580B1}} | |||
{{Cl|FOR}} n = row {{Cl|TO}} row + {{Text|20|#F580B1}} | |||
{{Cl|PRINT}} Array$(n) | |||
{{Cl|NEXT}} | |||
{{Cl|END IF}} | |||
{{Cl|END IF}} | |||
prevrow = row {{Text|<nowiki>'store previous row value</nowiki>|#919191}} | |||
{{Cl|LOOP}} | |||
{{Cl|LOOP | {{Cl|DO...LOOP|LOOP UNTIL}} {{Cl|INKEY$}} > {{Text|<nowiki>""</nowiki>|#FFB100}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{ | {{Small|Example by Ted Weissgerber}} | ||
{{PageSeeAlso}} | {{PageSeeAlso}} | ||
* [https://qb64phoenix.com/forum/showthread.php?tid=1302 Featured in our "Keyword of the Day" series] | |||
* [[_MOUSEX]], [[_MOUSEY]], [[_MOUSEBUTTON]] | * [[_MOUSEX]], [[_MOUSEY]], [[_MOUSEBUTTON]] | ||
* [[_MOUSEINPUT]], [[_MOUSEMOVE]] | * [[_MOUSEINPUT]], [[_MOUSEMOVE]] |
Latest revision as of 18:15, 25 May 2024
The _MOUSEWHEEL function returns a positive or negative INTEGER value indicating mouse scroll events since the last read of _MOUSEINPUT.
Syntax
- scrollAmount% = _MOUSEWHEEL
Description
- Returns -1 when scrolling up and 1 when scrolling down with 0 indicating no movement since last read.
- After an event has been read, the value resets to 0 automatically so cumulative position values must be added.
- If no movement on the wheel has occurred since the last _MOUSEINPUT read, _MOUSEWHEEL returns 0.
Availability
- Available for macOS since QB64-PE v3.13.0
Examples
- Example 1
- Reading the cumulative mouse wheel "clicks".
DO _LIMIT 50 DO WHILE _MOUSEINPUT Scroll = Scroll + _MOUSEWHEEL LOCATE 10, 20: PRINT Scroll LOOP LOOP UNTIL INKEY$ = CHR$(13) ' press Enter to quit |
- Example 2
- A simple text scrolling routine using the mouse wheel value to read a text array.
- You will need a text file that is large enough for this example.
DIM Array$(100) LINE INPUT "Enter a file name with 100 or more lines of text: ", file$ OPEN file$ FOR INPUT AS #1 DO UNTIL EOF(1) inputcount = inputcount + 1 LINE INPUT #1, Array$(inputcount) IF inputcount = 100 THEN EXIT DO LOOP FOR n = 1 TO 21: PRINT Array$(n): NEXT CLOSE #1 DO DO WHILE _MOUSEINPUT IF row >= 0 THEN row = row + _MOUSEWHEEL ELSE row = 0 'prevent under scrolling IF row > inputcount - 20 THEN row = inputcount - 20 'prevent over scrolling IF prevrow <> row THEN 'look for a change in row value IF row > 0 AND row <= inputcount - 20 THEN CLS: LOCATE 2, 1 FOR n = row TO row + 20 PRINT Array$(n) NEXT END IF END IF prevrow = row 'store previous row value LOOP LOOP UNTIL INKEY$ > "" |
See also
- Featured in our "Keyword of the Day" series
- _MOUSEX, _MOUSEY, _MOUSEBUTTON
- _MOUSEINPUT, _MOUSEMOVE
- _MOUSESHOW, _MOUSEHIDE
- Controller Devices