Difference between revisions of "MOUSEWHEEL"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>SMcNeill
m (-)
 
(26 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The '''_MOUSEWHEEL''' function returns a positive or negative {{KW|INTEGER}} value indicating the mouse scroll wheel clicks since the last mouse read.
+
{{DISPLAYTITLE:_MOUSEWHEEL}}
 +
The [[_MOUSEWHEEL]] function returns a positive or negative [[INTEGER]] value indicating mouse scroll events since the last read of [[_MOUSEINPUT]].
  
  
 
{{PageSyntax}}
 
{{PageSyntax}}
:<code>{{Parameter|scroll%}} = {{KW|_MOUSEWHEEL}}</code>
+
: {{Parameter|scrollAmount%}} = [[_MOUSEWHEEL]]
  
  
 
{{PageDescription}}
 
{{PageDescription}}
* Positive value of 1 represents one "click" the mouse wheel was moved down.
+
* Returns -1 when scrolling up and 1 when scrolling down with 0 indicating no movement since last read.
* Negative value of -1 represents one "click" the mouse wheel was moved up.
+
* After an event has been read, the value resets to 0 automatically so cumulative position values must be added.
* After a "click" has been read, the value resets to 0 automatically.
+
* 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 {{KW|_MOUSEINPUT}} read, _MOUSEWHEEL returns 0.
 
* You may want to use a cumulative mouse wheel scroll value using a total variable.
 
  
  
''Example:'' Reading the cumulative mouse wheel "clicks" (Enter quits).
+
{{PageExamples}}
 
+
''Example 1:'' Reading the cumulative mouse wheel "clicks".
{{CodeStart}}
+
{{CodeStart}} '' ''
  DO: K$ = INKEY$
+
  DO: {{Cl|_LIMIT}} 100
 
     DO WHILE {{Cl|_MOUSEINPUT}}
 
     DO WHILE {{Cl|_MOUSEINPUT}}
 
       Scroll = Scroll + {{Cl|_MOUSEWHEEL}}
 
       Scroll = Scroll + {{Cl|_MOUSEWHEEL}}
 
       LOCATE 10, 20: PRINT Scroll
 
       LOCATE 10, 20: PRINT Scroll
 
     LOOP
 
     LOOP
  LOOP UNTIL K$ = CHR$(13)
+
  LOOP UNTIL INKEY$ = CHR$(13) ' press Enter to quit '' ''
 
{{CodeEnd}}
 
{{CodeEnd}}
  
  
 
+
''Example 2:'' A simple text scrolling routine using the mouse wheel value to read a text array.
 +
{{CodeStart}} '' ''
 +
{{Cl|DIM}} Array$(100)
 +
{{Cl|LINE INPUT}} "Enter a file name with 100 or more lines of text: ", file$
 +
{{Cl|OPEN}} file$ {{Cl|FOR (file statement)|FOR}} {{Cl|INPUT (file mode)|INPUT}} {{Cl|AS}} #1
 +
{{Cl|DO...LOOP|DO}} {{Cl|UNTIL}} {{Cl|EOF}}(1)
 +
  inputcount = inputcount + 1
 +
  {{Cl|LINE INPUT (file statement)|LINE INPUT}} #1, Array$(inputcount)
 +
  {{Cl|IF...THEN|IF}} inputcount = 100 {{Cl|THEN}} {{Cl|EXIT DO}}
 +
{{Cl|LOOP}}
 +
{{Cl|FOR...NEXT|FOR}} n = 1 {{Cl|TO}} 21: {{Cl|PRINT}} Array$(n): {{Cl|NEXT}}
 +
{{Cl|CLOSE}} #1
 +
DO
 +
  {{Cl|DO...LOOP|DO}} {{Cl|WHILE}} {{Cl|_MOUSEINPUT}}
 +
    {{Cl|IF...THEN|IF}} row >= 0 {{Cl|THEN}} row = row + {{Cl|_MOUSEWHEEL}} {{Cl|ELSE}} row = 0  'prevent under scrolling
 +
    {{Cl|IF...THEN|IF}} row > inputcount - 20 {{Cl|THEN}} row = inputcount - 20    'prevent over scrolling
 +
    {{Cl|IF...THEN|IF}} prevrow <> row {{Cl|THEN}} 'look for a change in row value
 +
      {{Cl|IF...THEN|IF}} row > 0 {{Cl|AND (boolean)|AND}} row <= inputcount - 20 {{Cl|THEN}}
 +
        {{Cl|CLS}}: {{Cl|LOCATE}} 2, 1
 +
        {{Cl|FOR...NEXT|FOR}} n = row {{Cl|TO}} row + 20
 +
          {{Cl|PRINT}} Array$(n)
 +
        {{Cl|NEXT}}
 +
      {{Cl|END IF}}
 +
    {{Cl|END IF}}
 +
    prevrow = row 'store previous row value
 +
  {{Cl|LOOP}}
 +
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} > "" '' ''
 +
{{CodeEnd}}
 +
{{small|Code by Ted Weissgerber}}
 +
<center>Note: You will need a text file that is large enough for this example.</center>
  
  
 
{{PageSeeAlso}}
 
{{PageSeeAlso}}
*{{KW|_MOUSEX}}, {{KW|_MOUSEY}}, {{KW|_MOUSEBUTTON}}
+
* [[_MOUSEX]], [[_MOUSEY]], [[_MOUSEBUTTON]]
*{{KW|_MOUSEINPUT}}
+
* [[_MOUSEINPUT]], [[_MOUSEMOVE]]
*{{KW|_MOUSESHOW}}, {{KW|_MOUSEHIDE}}
+
* [[_MOUSESHOW]], [[_MOUSEHIDE]]
 +
* [[Controller Devices]]
  
  
 
{{PageNavigation}}
 
{{PageNavigation}}

Latest revision as of 17:46, 9 September 2017

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.


Examples

Example 1: Reading the cumulative mouse wheel "clicks".

DO: _LIMIT 100 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.

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$ > ""

Code by Ted Weissgerber
Note: You will need a text file that is large enough for this example.


See also



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page