Controller Devices: Difference between revisions
Jump to navigation
Jump to search
Program window pointer AXIS values change from 0 at the center to -1 or + 1 values at the window borders.
Note that middle _BUTTON(2) is equivalent to _MOUSEBUTTON(3)!
Relative WHEEL move values are negative when mouse is moved up or left. Positive when mouse is moved down or right.
WHEEL values can be added for a cumulative movement value when needed. Scroll reads can be off program screen.
Note: Some slide controls may only have one axis!
Code by Ted Weissgerber
_MOUSESHOW will return the mouse coordinate reads to the _AXIS control after it is used!
Wiki Pages
Main Page with Articles and Tutorials
QB64 specific keywords (alphabetical)
Original QBasic keywords (alphabetical)
QB64 OpenGL keywords (alphabetical)
Keywords by Usage
Got a question about something?
Frequently Asked Questions about QB64
QB64 Phoenix Edition Community Forum
Links to other QBasic Sites:
Pete's QBasic Forum
Pete's QBasic Downloads
(Created page with "QB64 supports all kinds of keyboard, mouse, joystick, gamepad, steering wheel and other multi-stick controller input devices. * '''In order to read the device controls, the number of input devices MUST first be found using _DEVICES.''' * After the device count is determined we can find out the type of device, the device name and the type of controls available using the _DEVICE$(device_number) function. The function returns a STRING containing information a...") |
No edit summary |
||
(16 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
QB64 supports all kinds of keyboard, mouse, joystick, gamepad, steering wheel and other multi-stick controller input devices. | QB64 supports all kinds of keyboard, mouse, joystick, gamepad, steering wheel and other multi-stick controller input devices. | ||
{| align="right" style="max-width:25%;" | |||
| __TOC__ | |||
|} | |||
* '''In order to read the device controls, the number of input devices MUST first be found using [[_DEVICES]].''' | * '''In order to read the device controls, the number of input devices MUST first be found using [[_DEVICES]].''' | ||
* After the device count is determined we can find out the type of device, the device name and the type of controls available using the [[_DEVICE$]](device_number) function. The function returns a [[STRING]] containing information about each numbered device. | * After the device count is determined we can find out the type of device, the device name and the type of controls available using the [[_DEVICE$]](device_number) function. The function returns a [[STRING]] containing information about each numbered device. | ||
:::'''{{Text|"[CONTROLLER]<nowiki>[</nowiki>[DEVICENAME] device description][BUTTON][AXIS][WHEEL]"|green}}''' | |||
:::'''{{ | |||
Line 17: | Line 15: | ||
:'''device = _DEVICEINPUT''' would return 1 for a keyboard event and 2 for a mouse event. | :'''device = _DEVICEINPUT''' would return 1 for a keyboard event and 2 for a mouse event. | ||
:'''mouse = _DEVICEINPUT(2)''' would return -1 | :'''mouse = _DEVICEINPUT(2)''' would return ''true(-1)'' when the mouse was moved, clicked or scrolled. | ||
== | == KEYBOARD == | ||
Normally the number 1 device, it usually only has [ | Normally the number 1 device, it usually only has [[BUTTON]] controls. Program window must be in focus to read key activity. | ||
:::: '''{{ | :::: '''{{Text|[KEYBOARD][BUTTON]|green}}''' | ||
Line 32: | Line 30: | ||
:: [[_BUTTON]](number) returns -1 when a button is pressed and 0 when released. | :: [[_BUTTON]](number) returns -1 when a button is pressed and 0 when released. | ||
{{ | {{FixedStart}} | ||
' '''Keyboard Device Button Numbers''' | |||
' | ' | ||
'''' | ' '''Esc F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 SysReq ScrL Pause''' | ||
' | ' 2 60 61 62 63 64 65 66 67 68 -- 88 89 -- 71 70 | ||
' | ' '''`~ 1! 2@ 3# 4$ 5% 6^ 7& 8* 9( 0) -_ =+ BkSpc Insert Home PgUp NumL / * -''' | ||
' | ' 42 3 4 5 6 7 8 9 10 11 12 13 14 15 339 328 330 326 310 56 75 | ||
' | ' '''Tab Q W E R T Y U I O P [{ ]} \| Delete End PgDn 7/Home 8/▲ 9/PU +''' | ||
' | ' 16 17 18 19 20 21 22 23 24 25 26 27 28 44 340 336 338 72 73 74 79 | ||
' | ' '''CapL A S D F G H J K L ;: '" Enter 4/◄- 5 6/-► E''' | ||
' | ' 59 31 32 33 34 35 36 37 38 39 40 41 29 76 77 78 '''n''' | ||
' | ' '''Shift Z X C V B N M ,< .> /? Shift ▲ 1/End 2/▼ 3/PD t''' | ||
' | ' 43 45 46 47 48 49 50 51 52 53 54 55 329 80 81 82 '''e''' | ||
' | ' '''Ctrl Win Alt Spacebar Alt Win Menu Ctrl ◄- ▼ -► 0/Insert ./Del r''' | ||
' | ' 30 348 -- 58 -- 349 350 286 332 337 334 83 84 285 | ||
' | ' | ||
{{FixedEnd}} | |||
<p style="text-align: center">([[#toc|Return to Table of Contents]])</p> | |||
== | == MOUSE == | ||
Normally the number 2 device, a mouse usually has [ | Normally the number 2 device, a mouse usually has [[[AXIS]]], [[[BUTTON]]] and [[[WHEEL]]] controls. Pointer must be in program screen area. | ||
:::: '''{{ | :::: '''{{Text|[MOUSE][BUTTON][AXIS][WHEEL]|green}}''' | ||
Line 62: | Line 61: | ||
:: [[_AXIS]](number) returns a [[SINGLE]] value from -1 to 1 with 0 representing the axis center in normal movement mode. | :: [[_AXIS]](number) returns a [[SINGLE]] value from -1 to 1 with 0 representing the axis center in normal movement mode. | ||
::: [[_AXIS]](1) returns the horizontal axis position in normal movement mode only. | ::: [[_AXIS]](1) returns the horizontal axis position in normal movement mode only. | ||
::: [[_AXIS]](2) returns the vertical axis position in normal movement mode only. | ::: [[_AXIS]](2) returns the vertical axis position in normal movement mode only. | ||
<center>Program window pointer AXIS values change from 0 at the center to -1 or + 1 values at the window borders.</center> | <center>Program window pointer AXIS values change from 0 at the center to -1 or + 1 values at the window borders.</center> | ||
Line 77: | Line 76: | ||
: [[_LASTWHEEL]](2) will normally return 3 wheels where the first two return relative coordinate movements when set. | : [[_LASTWHEEL]](2) will normally return 3 wheels where the first two return relative coordinate movements when set. | ||
:: [[_WHEEL]](number) returns -1 when wheel is scrolled up or forward and 1 when wheel is scrolled down or backward. | :: [[_WHEEL]](number) returns -1 when wheel is scrolled up or forward and 1 when wheel is scrolled down or backward. | ||
::: [[_WHEEL]](1) returns relative horizontal pixel moves after [[_MOUSEMOVEMENTX]] or Y enables relative mode. | ::: [[_WHEEL]](1) returns relative horizontal pixel moves after [[_MOUSEMOVEMENTX]] or Y enables relative mode. | ||
Line 89: | Line 88: | ||
<p style="text-align: center">([[#toc|Return to Table of Contents]])</p> | <p style="text-align: center">([[#toc|Return to Table of Contents]])</p> | ||
== | |||
== CONTROLLER == | |||
[[NAME][manufacturer name]] may follow in the controller [[_DEVICE$]] string. Devices can be joysticks, game pads or multi-stick. | [[NAME][manufacturer name]] may follow in the controller [[_DEVICE$]] string. Devices can be joysticks, game pads or multi-stick. | ||
:::: '''{{ | :::: '''{{Text|[CONTROLLER]<nowiki>[</nowiki>[DeviceName]description][BUTTON][AXIS][WHEEL]|green}}''' | ||
Normally device numbers 3 or higher, controllers may have any number of [ | Normally device numbers 3 or higher, controllers may have any number of [[[AXIS]]], [[[BUTTON]]] and/or [[[WHEEL]]] controls. | ||
Line 102: | Line 102: | ||
:: [[_AXIS]](number) returns a [[SINGLE]] value from -1 to 1 with 0 representing the axis center. | :: [[_AXIS]](number) returns a [[SINGLE]] value from -1 to 1 with 0 representing the axis center. | ||
::: [[_AXIS]](1) returns the horizontal axis position. | ::: [[_AXIS]](1) returns the horizontal axis position. | ||
::: [[_AXIS]](2) returns the vertical axis position. | ::: [[_AXIS]](2) returns the vertical axis position. | ||
<center>'''Note: Some slide controls may only have one axis!'''</center> | <center>'''Note: Some slide controls may only have one axis!'''</center> | ||
Line 112: | Line 112: | ||
: [[_LASTWHEEL]](device_number) will return the number of wheel controls a device has. | : [[_LASTWHEEL]](device_number) will return the number of wheel controls a device has. | ||
:: [[_WHEEL]](number) returns -1 when wheel is scrolled up or forward and 1 when wheel is scrolled down or backward. | :: [[_WHEEL]](number) returns -1 when wheel is scrolled up or forward and 1 when wheel is scrolled down or backward. | ||
<p style="text-align: center">([[#toc|Return to Table of Contents]])</p> | <p style="text-align: center">([[#toc|Return to Table of Contents]])</p> | ||
{{PageExamples}} | |||
: Displays all keyboard, mouse and game controller button, axis and wheel control input values when each device is being used. | : Displays all keyboard, mouse and game controller button, axis and wheel control input values when each device is being used. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|PRINT}} "Use relative mouse movement mode with ESC key exit only?(Y/N) "; | {{Cl|PRINT}} {{Text|<nowiki>"Use relative mouse movement mode with ESC key exit only?(Y/N) "</nowiki>|#FFB100}}; | ||
K$ = {{Cl|UCASE$}}({{Cl|INPUT$}}(1)) | K$ = {{Cl|UCASE$}}({{Cl|INPUT$}}({{Text|1|#F580B1}})) | ||
{{Cl|PRINT}} K$ | {{Cl|PRINT}} K$ | ||
{{Cl|PRINT}} | {{Cl|PRINT}} | ||
{{Cl | {{Cl|FOR}} i = {{Text|1|#F580B1}} {{Cl|TO}} {{Cl|_DEVICES}} {{Text|<nowiki>'DEVICES MUST be read first!</nowiki>|#919191}} | ||
{{Cl|PRINT}} {{Cl|STR$}}(i) + {{Text|<nowiki>") "</nowiki>|#FFB100}} + {{Cl|_DEVICE$}}(i) + {{Text|<nowiki>" Buttons:"</nowiki>|#FFB100}}; {{Cl|_LASTBUTTON}}(i); {{Text|<nowiki>",Axis:"</nowiki>|#FFB100}}; {{Cl|_LASTAXIS}}(i); {{Text|<nowiki>",Wheel:"</nowiki>|#FFB100}}; {{Cl|_LASTWHEEL}}(i) | |||
{{Cl|NEXT}} | {{Cl|NEXT}} | ||
{{Cl | {{Cl|IF}} K$ = {{Text|<nowiki>"Y"</nowiki>|#FFB100}} {{Cl|THEN}} dummy = {{Cl|_MOUSEMOVEMENTX}} {{Text|<nowiki>'enable relative mouse movement reads</nowiki>|#919191}} | ||
{{Cl|PRINT}} | {{Cl|PRINT}} | ||
{{Cl | {{Cl|DO}} | ||
x& = {{Cl|_DEVICEINPUT}} {{Text|<nowiki>'determines which device is currently being used</nowiki>|#919191}} | |||
{{Cl|IF}} x& = {{Text|1|#F580B1}} {{Cl|THEN}} | |||
{{Cl|PRINT}} {{Text|<nowiki>"Keyboard: "</nowiki>|#FFB100}}; | |||
{{Cl|FOR}} b = {{Text|1|#F580B1}} {{Cl|TO}} {{Cl|_LASTBUTTON}}(x&) | |||
bb = {{Cl|_BUTTONCHANGE}}(b) | |||
{{Cl|IF}} bb {{Cl|THEN}} {{Cl|PRINT}} b; bb; {{Cl|_BUTTON}}(b); | |||
{{Cl|NEXT}} | |||
{{Cl|PRINT}} | |||
{{Cl|END IF}} | |||
{{Cl|IF}} x& > {{Text|1|#F580B1}} {{Cl|THEN}} {{Text|<nowiki>' skip keyboard reads</nowiki>|#919191}} | |||
{{Cl|PRINT}} {{Text|<nowiki>"Device:"</nowiki>|#FFB100}}; x&; | |||
{{Cl|FOR}} b = {{Text|1|#F580B1}} {{Cl|TO}} {{Cl|_LASTBUTTON}}(x&) | |||
{{Cl|PRINT}} {{Cl|_BUTTONCHANGE}}(b); {{Cl|_BUTTON}}(b); | |||
{{Cl|NEXT}} | |||
{{Cl|FOR}} a = {{Text|1|#F580B1}} {{Cl|TO}} {{Cl|_LASTAXIS}}(x&) | |||
{{Cl|PRINT}} {{Cl|_AXIS}}(a); {{Text|<nowiki>'mouse axis returns -1 to 1 with 0 center screen</nowiki>|#919191}} | |||
{{Cl|NEXT}} | |||
{{Cl|FOR}} w = {{Text|1|#F580B1}} {{Cl|TO}} {{Cl|_LASTWHEEL}}(x&) | |||
{{Cl|PRINT}} {{Cl|_WHEEL}}(w); {{Text|<nowiki>'wheels 1 and 2 of mouse return relative pixel moves when enabled</nowiki>|#919191}} | |||
{{Cl|NEXT}} | |||
{{Cl|PRINT}} | |||
{{Cl|END IF}} | |||
{{Cl|LOOP | {{Cl|DO...LOOP|LOOP UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}({{Text|27|#F580B1}}) {{Text|<nowiki>'escape key exit</nowiki>|#919191}} | ||
{{Cl|END}} | {{Cl|END}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{ | {{Small|Code by Ted Weissgerber}} | ||
:: ''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. | ||
: Using [[_MOUSEMOVEMENTX]] or Y will hide the mouse cursor and return relative mouse movements with the 1 and 2 [[_WHEEL]] controls. | : Using [[_MOUSEMOVEMENTX]] or Y will hide the mouse cursor and return relative mouse movements with the 1 and 2 [[_WHEEL]] controls. | ||
Line 165: | Line 165: | ||
<p style="text-align: center">([[#toc|Return to Table of Contents]])</p> | <p style="text-align: center">([[#toc|Return to Table of Contents]])</p> | ||
{{PageSeeAlso}} | |||
* [[_DEVICEINPUT]], [[_AXIS]], [[_BUTTON]], [[_BUTTONCHANGE]], [[_WHEEL]] | * [[_DEVICEINPUT]], [[_AXIS]], [[_BUTTON]], [[_BUTTONCHANGE]], [[_WHEEL]] | ||
* [[_DEVICES]], [[_DEVICE$]], [[_LASTAXIS]], [[_LASTBUTTON]], [[_LASTWHEEL]] | * [[_DEVICES]], [[_DEVICE$]], [[_LASTAXIS]], [[_LASTBUTTON]], [[_LASTWHEEL]] | ||
* [[_MOUSEINPUT]], [[_MOUSEX]], [[_MOUSEY]], [[_MOUSEBUTTON]], [[_MOUSEWHEEL]] | * [[_MOUSEINPUT]], [[_MOUSEX]], [[_MOUSEY]], [[_MOUSEBUTTON]], [[_MOUSEWHEEL]] | ||
* [[_MOUSEMOVE]], [[_MOUSEHIDE]], [[_MOUSESHOW]] | * [[_MOUSEMOVE]], [[_MOUSEHIDE]], [[_MOUSESHOW]] | ||
* [[_MOUSEMOVEMENTX]], [[_MOUSEMOVEMENTY]] {{ | * [[_MOUSEMOVEMENTX]], [[_MOUSEMOVEMENTY]] {{Text|(relative movement)}} | ||
* [[STRIG]] {{ | * [[STRIG]] {{Text|(button)}}, [[STICK]] {{Text|(axis)}} | ||
{{ | {{PageReferences}} |
Latest revision as of 13:13, 19 November 2024
QB64 supports all kinds of keyboard, mouse, joystick, gamepad, steering wheel and other multi-stick controller input devices.
- In order to read the device controls, the number of input devices MUST first be found using _DEVICES.
- After the device count is determined we can find out the type of device, the device name and the type of controls available using the _DEVICE$(device_number) function. The function returns a STRING containing information about each numbered device.
- "[CONTROLLER][[DEVICENAME] device description][BUTTON][AXIS][WHEEL]"
- _DEVICEINPUT can indicate a used device number or true when a specified device number is active.
- device = _DEVICEINPUT would return 1 for a keyboard event and 2 for a mouse event.
- mouse = _DEVICEINPUT(2) would return true(-1) when the mouse was moved, clicked or scrolled.
KEYBOARD
Normally the number 1 device, it usually only has BUTTON controls. Program window must be in focus to read key activity.
- [KEYBOARD][BUTTON]
- _LASTBUTTON(1) will normally return 512 buttons.
- _BUTTONCHANGE(number) returns -1 when pressed, 1 when released and 0 when there is no event since the last read.
- _BUTTON(number) returns -1 when a button is pressed and 0 when released.
' Keyboard Device Button Numbers ' ' Esc F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 SysReq ScrL Pause ' 2 60 61 62 63 64 65 66 67 68 -- 88 89 -- 71 70 ' `~ 1! 2@ 3# 4$ 5% 6^ 7& 8* 9( 0) -_ =+ BkSpc Insert Home PgUp NumL / * - ' 42 3 4 5 6 7 8 9 10 11 12 13 14 15 339 328 330 326 310 56 75 ' Tab Q W E R T Y U I O P [{ ]} \| Delete End PgDn 7/Home 8/▲ 9/PU + ' 16 17 18 19 20 21 22 23 24 25 26 27 28 44 340 336 338 72 73 74 79 ' CapL A S D F G H J K L ;: '" Enter 4/◄- 5 6/-► E ' 59 31 32 33 34 35 36 37 38 39 40 41 29 76 77 78 n ' Shift Z X C V B N M ,< .> /? Shift ▲ 1/End 2/▼ 3/PD t ' 43 45 46 47 48 49 50 51 52 53 54 55 329 80 81 82 e ' Ctrl Win Alt Spacebar Alt Win Menu Ctrl ◄- ▼ -► 0/Insert ./Del r ' 30 348 -- 58 -- 349 350 286 332 337 334 83 84 285 ' |
MOUSE
Normally the number 2 device, a mouse usually has [[[AXIS]]], [[[BUTTON]]] and [[[WHEEL]]] controls. Pointer must be in program screen area.
- [MOUSE][BUTTON][AXIS][WHEEL]
- _LASTAXIS(2) normally returns 2 axis representing the horizontal and vertical mouse, trackball, touch pad or touchscreen axis.
- _LASTBUTTON(2) will normally return 3 buttons when mouse has a center or scroll wheel button.
- _BUTTONCHANGE(number) returns -1 when pressed, 1 when released and 0 when there is no event since the last read.
- _BUTTON(number) returns -1 when corresponding button is pressed and 0 when released.
- _BUTTON(1) returns Left button presses like _MOUSEBUTTON(1) and _BUTTONCHANGE(1) returns events.
- _BUTTON(2) returns Center button presses like _MOUSEBUTTON(3) and _BUTTONCHANGE(2) returns events.
- _BUTTON(3) returns Right button presses like _MOUSEBUTTON(2) and _BUTTONCHANGE(3) returns events.
- _LASTWHEEL(2) will normally return 3 wheels where the first two return relative coordinate movements when set.
- _WHEEL(number) returns -1 when wheel is scrolled up or forward and 1 when wheel is scrolled down or backward.
- _WHEEL(1) returns relative horizontal pixel moves after _MOUSEMOVEMENTX or Y enables relative mode.
- _WHEEL(2) returns relative vertical pixel moves after _MOUSEMOVEMENTX or Y enables relative mode.
- _WHEEL(3) returns -1 when scroll wheel is moved forward or up and 1 when scrolled backward or down.
- _WHEEL(number) returns -1 when wheel is scrolled up or forward and 1 when wheel is scrolled down or backward.
CONTROLLER
[[NAME][manufacturer name]] may follow in the controller _DEVICE$ string. Devices can be joysticks, game pads or multi-stick.
- [CONTROLLER][[DeviceName]description][BUTTON][AXIS][WHEEL]
Normally device numbers 3 or higher, controllers may have any number of [[[AXIS]]], [[[BUTTON]]] and/or [[[WHEEL]]] controls.
- _LASTAXIS(device_number) normally returns dual axis representing the horizontal and vertical axis or view point("top hat").
- _LASTBUTTON(device_number) will return the number of buttons or triggers a device has.
- _BUTTONCHANGE(number) returns -1 when pressed, 1 when released and 0 when there is no event since the last read.
- _BUTTON(number) returns -1 when button number is pressed and 0 when released.
- _LASTWHEEL(device_number) will return the number of wheel controls a device has.
- _WHEEL(number) returns -1 when wheel is scrolled up or forward and 1 when wheel is scrolled down or backward.
Examples
- Displays all keyboard, mouse and game controller button, axis and wheel control input values when each device is being used.
PRINT "Use relative mouse movement mode with ESC key exit only?(Y/N) "; K$ = UCASE$(INPUT$(1)) PRINT K$ PRINT FOR i = 1 TO _DEVICES 'DEVICES MUST be read first! PRINT STR$(i) + ") " + _DEVICE$(i) + " Buttons:"; _LASTBUTTON(i); ",Axis:"; _LASTAXIS(i); ",Wheel:"; _LASTWHEEL(i) NEXT IF K$ = "Y" THEN dummy = _MOUSEMOVEMENTX 'enable relative mouse movement reads PRINT DO x& = _DEVICEINPUT 'determines which device is currently being used IF x& = 1 THEN PRINT "Keyboard: "; FOR b = 1 TO _LASTBUTTON(x&) bb = _BUTTONCHANGE(b) IF bb THEN PRINT b; bb; _BUTTON(b); NEXT PRINT END IF IF x& > 1 THEN ' skip keyboard reads PRINT "Device:"; x&; FOR b = 1 TO _LASTBUTTON(x&) PRINT _BUTTONCHANGE(b); _BUTTON(b); NEXT FOR a = 1 TO _LASTAXIS(x&) PRINT _AXIS(a); 'mouse axis returns -1 to 1 with 0 center screen NEXT FOR w = 1 TO _LASTWHEEL(x&) PRINT _WHEEL(w); 'wheels 1 and 2 of mouse return relative pixel moves when enabled 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.
- Using _MOUSEMOVEMENTX or Y will hide the mouse cursor and return relative mouse movements with the 1 and 2 _WHEEL controls.
See also
- _DEVICEINPUT, _AXIS, _BUTTON, _BUTTONCHANGE, _WHEEL
- _DEVICES, _DEVICE$, _LASTAXIS, _LASTBUTTON, _LASTWHEEL
- _MOUSEINPUT, _MOUSEX, _MOUSEY, _MOUSEBUTTON, _MOUSEWHEEL
- _MOUSEMOVE, _MOUSEHIDE, _MOUSESHOW
- _MOUSEMOVEMENTX, _MOUSEMOVEMENTY (relative movement)
- STRIG (button), STICK (axis)