DEVICE$: 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
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 15: | Line 15: | ||
::: [CONTROLLER] subsequent devices are listed as controllers which include joysticks and game pads. | ::: [CONTROLLER] subsequent devices are listed as controllers which include joysticks and game pads. | ||
::* When [CONTROLLER] is returned it may also give the [[STRING]] [[NAME] [device description]] of the controller. | ::* When [CONTROLLER] is returned it may also give the [[STRING]] [[NAME] [device description]] of the controller. | ||
::* When [DISCONNECTED] is returned, then the device was unplugged after device init. | |||
::* Returns the type of input after the device name as one or more of the following types: | ::* Returns the type of input after the device name as one or more of the following types: | ||
::: [ | ::: [[[BUTTON]]] indicates there are button types of input. [[_LASTBUTTON]] can return the number of buttons available. | ||
::: [ | ::: [[[AXIS]]] indicates there are stick types of input. [[_LASTAXIS]] can return the number of axis available. | ||
::: [ | ::: [[[WHEEL]]] indicates that a scrolling input can be read. [[_LASTWHEEL]] can return the number of wheels available. | ||
* '''Device numbers above the number of [[_DEVICES|devices]] found will return an OS error.''' | * '''Device numbers above the number of [[_DEVICES|devices]] found will return an OS error.''' | ||
Line 27: | Line 28: | ||
''Example 1:'' Checking for the system's input devices and the number of buttons available. | ''Example 1:'' Checking for the system's input devices and the number of buttons available. | ||
{{CodeStart}} | {{CodeStart}} | ||
devices = {{Cl|_DEVICES}} | devices = {{Cl|_DEVICES}} {{Text|<nowiki>'MUST be read in order for other 2 device functions to work!</nowiki>|#919191}} | ||
PRINT "Number of input devices found ="; devices | {{Cl|PRINT}} {{Text|<nowiki>"Number of input devices found ="</nowiki>|#FFB100}}; devices | ||
FOR i = 1 TO devices | {{Cl|FOR}} i = {{Text|1|#F580B1}} {{Cl|TO}} devices | ||
{{Cl|PRINT}} {{Cl|_DEVICE$}}(i) | |||
{{Cl|PRINT}} {{Text|<nowiki>"Buttons:"</nowiki>|#FFB100}}; {{Cl|_LASTBUTTON}}(i); {{Text|<nowiki>"Axis:"</nowiki>|#FFB100}}; {{Cl|_LASTAXIS}}(i); {{Text|<nowiki>"Wheels:"</nowiki>|#FFB100}}; {{Cl|_LASTWHEEL}}(i) | |||
NEXT | {{Cl|NEXT}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{OutputStart}}Number of input devices found = 3 | {{OutputStart}}Number of input devices found = 3 | ||
Line 44: | Line 45: | ||
:Note: The [[STRIG]]/[[STICK]] commands won't read from the keyboard or mouse device the above example lists. They will only work on controllers. | :Note: The [[STRIG]]/[[STICK]] commands won't read from the keyboard or mouse device the above example lists. They will only work on controllers. | ||
---- | |||
''Example 2:'' Finding the number of mouse buttons available in QB64. This could also be used for other devices. | ''Example 2:'' Finding the number of mouse buttons available in QB64. This could also be used for other devices. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl | {{Cl|FOR}} d = {{Text|1|#F580B1}} {{Cl|TO}} {{Cl|_DEVICES}} {{Text|<nowiki>'number of input devices found</nowiki>|#919191}} | ||
dev$ = {{Cl|_DEVICE$}}(d) | |||
{{Cl|IF}} {{Cl|INSTR}}(dev$, {{Text|<nowiki>"[MOUSE]"</nowiki>|#FFB100}}) {{Cl|THEN}} buttons = {{Cl|_LASTBUTTON}}(d): {{Cl|EXIT FOR}} | |||
{{Cl|NEXT}} | {{Cl|NEXT}} | ||
{{Cl|PRINT}} buttons; "mouse buttons available" | {{Cl|PRINT}} buttons; {{Text|<nowiki>"mouse buttons available"</nowiki>|#FFB100}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
Latest revision as of 21:29, 22 May 2023
The _DEVICE$ function returns a STRING value holding the controller type, name and input types of the input devices on a computer.
Syntax
- device$ = _DEVICE$(device_number)
- The _DEVICES function must be read first to get the number of devices and to enable _DEVICE$ and _DEVICEINPUT.
- The device_number parameter indicates the number of the controller device to be read.
- Returns the STRING control type, name of the device and input types each can use included in brackets:
- Control type:
- [KEYBOARD] always listed as first device when keyboard(s) available. Only one keyboard will show.
- [MOUSE]] always listed as second device when keyboard(s) and mouse(mice) are available. Only one mouse will show.
- [CONTROLLER] subsequent devices are listed as controllers which include joysticks and game pads.
- When [CONTROLLER] is returned it may also give the STRING [[NAME] [device description]] of the controller.
- When [DISCONNECTED] is returned, then the device was unplugged after device init.
- Returns the type of input after the device name as one or more of the following types:
- [[[BUTTON]]] indicates there are button types of input. _LASTBUTTON can return the number of buttons available.
- [[[AXIS]]] indicates there are stick types of input. _LASTAXIS can return the number of axis available.
- [[[WHEEL]]] indicates that a scrolling input can be read. _LASTWHEEL can return the number of wheels available.
- Device numbers above the number of devices found will return an OS error.
- Devices found include keyboard, mouse, joysticks, game pads and multiple stick game controllers.
Examples
Example 1: Checking for the system's input devices and the number of buttons available.
devices = _DEVICES 'MUST be read in order for other 2 device functions to work! PRINT "Number of input devices found ="; devices FOR i = 1 TO devices PRINT _DEVICE$(i) PRINT "Buttons:"; _LASTBUTTON(i); "Axis:"; _LASTAXIS(i); "Wheels:"; _LASTWHEEL(i) NEXT |
Number of input devices found = 3 [KEYBOARD][BUTTON] Buttons: 512 Axis: 0 Wheels: 0 [MOUSE][BUTTON][AXIS][WHEEL] Buttons: 3 Axis: 2 Wheels: 3 [CONTROLLER][[NAME][Microsoft Sidewinder Precision Pro (USB)]][BUTTON][AXIS] Buttons: 9 Axis: 6 Wheels: 0 |
- Note: The STRIG/STICK commands won't read from the keyboard or mouse device the above example lists. They will only work on controllers.
Example 2: Finding the number of mouse buttons available in QB64. This could also be used for other devices.
FOR d = 1 TO _DEVICES 'number of input devices found dev$ = _DEVICE$(d) IF INSTR(dev$, "[MOUSE]") THEN buttons = _LASTBUTTON(d): EXIT FOR NEXT PRINT buttons; "mouse buttons available" |
See also
- _DEVICES, _DEVICEINPUT
- _LASTBUTTON, _LASTAXIS, _LASTWHEEL
- _BUTTON, _BUTTONCHANGE
- _AXIS, _WHEEL
- _MOUSEBUTTON
- STRIG, STICK
- ON STRIG(n), STRIG(n)
- Controller Devices