The _DEVICEINPUT function returns the device number when a controller device button, wheel or axis event occurs.
Syntax
- device% = _DEVICEINPUT
- device_active% = _DEVICEINPUT(device_number%)
Parameters
- Use the device% INTEGER returned to find the number of the controller device being used.
- A literal specific device_number% parameter can be used to return -1 if active or 0 if inactive, e.g. WHILE _DEVICEINPUT(2).
Description
- Use _DEVICES to find the number of controller devices available BEFORE using this function.
- _DEVICE$ can be used to list the device names and control types using valid _DEVICES numbers.
- When a device button is pressed or a scroll wheel or axis is moved, the device number will be returned.
- Devices are numbered as 1 for keyboard and 2 for mouse. Other controller devices will be numbered 3 or higher if installed.
- _LASTBUTTON, _LASTAXIS, or _LASTWHEEL will indicate the number of functions available with the specified device% number.
- User input events can be monitored reading valid numbered _AXIS, _BUTTON, _BUTTONCHANGE or _WHEEL functions.
- ON _DEVICEINPUT GOSUB keyboard, mouse, gamecontrol could be used to easily branch to device specific handler routines (see Example 3 below).
Examples
- Example 1
- Checking device controller interfaces and finding out what devices are being used.
[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
Device = 2 Device = 2
|
Note:
Mouse events must be within the program screen area. Keyboard presses
are registered only when program is in focus.
|
- Example 2
- Why does a mouse have 3 wheels? Relative x and y movements can be read using the first 2 _WHEEL reads.
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 (true) only when the mouse is moved,
scrolled or clicked.
|
- Example 3
- Using ON...GOSUB with the _DEVICEINPUT number to add keyboard, mouse and game controller event procedures.
Code by Ted Weissgerber
Note: ON...GOSUB and ON...GOTO events require numerical
values to match the order of line labels listed in the event used inside
loops.
|