2016-03-18 11:36:04 +00:00
|
|
|
{{DISPLAYTITLE:_DEVICE$}}
|
2015-08-02 12:12:44 +00:00
|
|
|
The '''_DEVICE$''' function returns a [[STRING]] value holding the controller type, name and input types of the input devices on a computer.
|
|
|
|
|
|
|
|
|
|
|
|
{{PageSyntax}}
|
2017-10-10 14:55:21 +00:00
|
|
|
: {{Parameter|device$}} = _DEVICE$({{Parameter|device_number}})
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
2017-10-10 14:55:21 +00:00
|
|
|
* The '''[[_DEVICES]] function must be read first to get the number of devices and to enable [[_DEVICE$]] and [[_DEVICEINPUT]].'''
|
|
|
|
* The {{Parameter|device_number}} parameter indicates the number of the controller device to be read.
|
2015-08-02 12:12:44 +00:00
|
|
|
* Returns the [[STRING]] control type, name of the device and input types each can use included in brackets:
|
|
|
|
::* Control type:
|
2016-03-18 11:36:04 +00:00
|
|
|
::: [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.
|
2015-08-02 12:12:44 +00:00
|
|
|
::: [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.
|
|
|
|
::* Returns the type of input after the device name as one or more of the following types:
|
|
|
|
::: [{{KW|BUTTON}}] indicates there are button types of input. [[_LASTBUTTON]] can return the number of buttons available.
|
|
|
|
::: [{{KW|AXIS}}] indicates there are stick types of input. [[_LASTAXIS]] can return the number of axis available.
|
|
|
|
::: [{{KW|WHEEL}}] indicates that a scrolling input can be read. [[_LASTWHEEL]] can return the number of wheels available.
|
|
|
|
|
2017-10-10 14:55:21 +00:00
|
|
|
* '''Device numbers above the number of [[_DEVICES|devices]] found will return an OS error.'''
|
2015-08-02 12:12:44 +00:00
|
|
|
* Devices found include keyboard, mouse, joysticks, game pads and multiple stick game controllers.
|
|
|
|
|
|
|
|
|
2017-10-10 14:55:21 +00:00
|
|
|
{{PageExamples}}
|
2015-08-02 12:12:44 +00:00
|
|
|
''Example 1:'' Checking for the system's input devices and the number of buttons available.
|
|
|
|
{{CodeStart}} '' ''
|
|
|
|
devices = {{Cl|_DEVICES}} 'MUST be read in order for other 2 device functions to work!
|
2019-04-15 01:15:33 +00:00
|
|
|
PRINT "Number of input devices found ="; devices
|
2015-08-02 12:12:44 +00:00
|
|
|
FOR i = 1 TO devices
|
|
|
|
PRINT {{Cl|_DEVICE$}}(i)
|
2019-04-15 01:15:33 +00:00
|
|
|
PRINT "Buttons:"; {{Cl|_LASTBUTTON}}(i); "Axis:"; {{Cl|_LASTAXIS}}(i); "Wheels:"; {{Cl|_LASTWHEEL}}(i)
|
2015-08-02 12:12:44 +00:00
|
|
|
NEXT '' ''
|
|
|
|
{{CodeEnd}}
|
|
|
|
{{OutputStart}}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
|
|
|
|
{{OutputEnd}}
|
2016-03-18 11:36:04 +00:00
|
|
|
:Note: The [[STRIG]]/[[STICK]] commands won't read from the keyboard or mouse device the above example lists. They will only work on controllers.
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
''Example 2:'' Finding the number of mouse buttons available in QB64. This could also be used for other devices.
|
|
|
|
{{CodeStart}} '' ''
|
|
|
|
{{Cl|FOR...NEXT|FOR}} d = 1 {{Cl|TO}} {{Cl|_DEVICES}} 'number of input devices found
|
|
|
|
dev$ = {{Cl|_DEVICE$}}(d)
|
2019-04-15 01:15:33 +00:00
|
|
|
{{Cl|IF...THEN|IF}} {{Cl|INSTR}}(dev$, "[MOUSE]") {{Cl|THEN}} buttons = {{Cl|_LASTBUTTON}}(d): {{Cl|EXIT}} {{Cl|FOR...NEXT|FOR}}
|
2015-08-02 12:12:44 +00:00
|
|
|
{{Cl|NEXT}}
|
2019-04-15 01:15:33 +00:00
|
|
|
{{Cl|PRINT}} buttons; "mouse buttons available" '' ''
|
2015-08-02 12:12:44 +00:00
|
|
|
{{CodeEnd}}
|
|
|
|
|
|
|
|
|
2017-10-10 14:55:21 +00:00
|
|
|
{{PageSeeAlso}}
|
2015-08-02 12:12:44 +00:00
|
|
|
* [[_DEVICES]], [[_DEVICEINPUT]]
|
|
|
|
* [[_LASTBUTTON]], [[_LASTAXIS]], [[_LASTWHEEL]]
|
|
|
|
* [[_BUTTON]], [[_BUTTONCHANGE]]
|
|
|
|
* [[_AXIS]], [[_WHEEL]]
|
|
|
|
* [[_MOUSEBUTTON]]
|
|
|
|
* [[STRIG]], [[STICK]]
|
|
|
|
* [[ON STRIG(n)]], [[STRIG(n)]]
|
|
|
|
* [[Controller Devices]]
|
|
|
|
|
|
|
|
|
2019-04-15 01:15:33 +00:00
|
|
|
{{PageNavigation}}
|