WHEEL: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "{{DISPLAYTITLE:_WHEEL}} The _WHEEL function returns the relative position of a specified wheel number on a controller device. {{PageSyntax}} : {{Parameter|move}} = _WHEEL({{Parameter|wheelNumber%}}) * Returns -1 when scrolling up and 1 when scrolling down with 0 indicating no movement since last read. * Add consecutive wheel values to determine a cumulative value over time for scrolling or moving objects. * {{Parameter|wheelNumber%}} must be a number which do...") |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 16: | Line 16: | ||
{{PageExamples}} | {{PageExamples}} | ||
''Example 1:'' Reading multiple controller device buttons, axis and wheels. | ''Example 1:'' Reading multiple controller device buttons, axis and wheels. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|FOR...NEXT|FOR}} i = 1 {{Cl|TO}} {{Cl|_DEVICES}} | {{Cl|FOR...NEXT|FOR}} i = 1 {{Cl|TO}} {{Cl|_DEVICES}} | ||
{{Cl|PRINT}} {{Cl|STR$}}(i) + ") " + {{Cl|_DEVICE$}}(i) + " Buttons:"; {{Cl|_LASTBUTTON}}(i); ",Axis:"; {{Cl|_LASTAXIS}}(i); ",Wheel:"; {{Cl|_LASTWHEEL}}(i) | {{Cl|PRINT}} {{Cl|STR$}}(i) + ") " + {{Cl|_DEVICE$}}(i) + " Buttons:"; {{Cl|_LASTBUTTON}}(i); ",Axis:"; {{Cl|_LASTAXIS}}(i); ",Wheel:"; {{Cl|_LASTWHEEL}}(i) | ||
Line 38: | Line 38: | ||
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}(27) 'escape key exit | {{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}(27) 'escape key exit | ||
{{Cl|END}} | {{Cl|END}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
: ''Note:'' When there is no device control to read, a [[FOR...NEXT|FOR]] n = 1 TO 0 loop will not run thus avoiding a control function read error. | : ''Note:'' When there is no device control to read, a [[FOR...NEXT|FOR]] n = 1 TO 0 loop will not run thus avoiding a control function read error. | ||
Line 44: | Line 44: | ||
''Example 2:'' Why does a mouse have 3 wheels? Relative x and y movements can be read using the first 2 _WHEEL reads. | ''Example 2:'' Why does a mouse have 3 wheels? Relative x and y movements can be read using the first 2 _WHEEL reads. | ||
{{CodeStart}} | {{CodeStart}} | ||
ignore = {{Cl|_MOUSEMOVEMENTX}} 'dummy call to put mouse into relative movement mode | ignore = {{Cl|_MOUSEMOVEMENTX}} 'dummy call to put mouse into relative movement mode | ||
Line 53: | Line 53: | ||
{{Cl|DO...LOOP|DO}} {{Cl|WHILE}} {{Cl|_DEVICEINPUT}}(2) 'loop only runs during a device 2 mouse event | {{Cl|DO...LOOP|DO}} {{Cl|WHILE}} {{Cl|_DEVICEINPUT}}(2) 'loop only runs during a device 2 mouse event | ||
{{Cl|PRINT}} {{Cl|_WHEEL}}(1), {{Cl|_WHEEL}}(2), {{Cl|_WHEEL}}(3) | {{Cl|PRINT}} {{Cl|_WHEEL}}(1), {{Cl|_WHEEL}}(2), {{Cl|_WHEEL}}(3) | ||
{{Cl|LOOP}} | {{Cl|LOOP}} | ||
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}(27) | {{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}(27) | ||
{{CodeEnd}} | {{CodeEnd}} | ||
: ''Explanation:'' Referencing the [[_MOUSEMOVEMENTX]] function hides the mouse and sets the mouse to a relative movement mode which can be read by [[_WHEEL]]. [[_DEVICEINPUT]](2) returns -1 | : ''Explanation:'' Referencing the [[_MOUSEMOVEMENTX]] function hides the mouse and sets the mouse to a relative movement mode which can be read by [[_WHEEL]]. [[_DEVICEINPUT]](2) returns ''true(-1)'' only when the mouse is moved, scrolled or clicked. | ||
Latest revision as of 00:35, 18 November 2024
The _WHEEL function returns the relative position of a specified wheel number on a controller device.
Syntax
- move = _WHEEL(wheelNumber%)
- Returns -1 when scrolling up and 1 when scrolling down with 0 indicating no movement since last read.
- Add consecutive wheel values to determine a cumulative value over time for scrolling or moving objects.
- wheelNumber% must be a number which does not exceed the number of wheels found by the _LASTWHEEL function.
- When a mouse indicates it has 3 wheels, the first two are for relative movement reads. The third wheel is for scrolling.
- The number of _DEVICES must be read before using _DEVICE$, _DEVICEINPUT or _LASTWHEEL.
Examples
Example 1: Reading multiple controller device buttons, axis and wheels.
FOR i = 1 TO _DEVICES PRINT STR$(i) + ") " + _DEVICE$(i) + " Buttons:"; _LASTBUTTON(i); ",Axis:"; _LASTAXIS(i); ",Wheel:"; _LASTWHEEL(i) NEXT DO d& = _DEVICEINPUT IF d& THEN ' the device number cannot be zero! PRINT "Found"; d&; FOR b = 1 TO _LASTBUTTON(d&) PRINT _BUTTONCHANGE(b); _BUTTON(b); NEXT FOR a = 1 TO _LASTAXIS(d&) PRINT _AXIS(a); NEXT FOR w = 1 TO _LASTWHEEL(d&) PRINT _WHEEL(w); NEXT PRINT END IF LOOP UNTIL INKEY$ = CHR$(27) 'escape key exit END |
- Note: When there is no device control to read, a FOR n = 1 TO 0 loop will not run thus avoiding a control function read error.
Example 2: Why does a mouse have 3 wheels? Relative x and y movements can be read using the first 2 _WHEEL reads.
ignore = _MOUSEMOVEMENTX 'dummy call to put mouse into relative movement mode PRINT "Move your mouse and/or your mouse wheel (ESC to exit)" d = _DEVICES ' always read number of devices to enable device input DO: _LIMIT 30 'main loop DO WHILE _DEVICEINPUT(2) 'loop only runs during a device 2 mouse event PRINT _WHEEL(1), _WHEEL(2), _WHEEL(3) LOOP LOOP UNTIL INKEY$ = CHR$(27) |
- Explanation: Referencing the _MOUSEMOVEMENTX function hides the mouse and sets the mouse to a relative movement mode which can be read by _WHEEL. _DEVICEINPUT(2) returns true(-1) only when the mouse is moved, scrolled or clicked.
See also
- _MOUSEWHEEL
- _LASTWHEEL, _LASTBUTTON, _LASTAXIS
- _AXIS, _BUTTON, _BUTTONCHANGE
- _DEVICES, _DEVICE$, _DEVICEINPUT
- _MOUSEMOVEMENTX, _MOUSEMOVEMENTY
- Controller Devices