_DEVICEINPUT - mkilgore/QB64pe GitHub Wiki
The _DEVICEINPUT function returns the device number when a controller device button, wheel or axis event occurs.
- device% = _DEVICEINPUT
- device_active% = _DEVICEINPUT(device_number%)
- Use the _DEVICEINPUT 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. EX: WHILE _DEVICEINPUT(2)
- 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.
- Note: ON _DEVICEINPUT GOSUB keyboard, mouse, gamecontrol can be used to control the devices 1,2 and 3, etc.
Example 1: Checking device controller interfaces and finding out what devices are being used.
PRINT DO x = _DEVICEINPUT IF...THEN x THEN PRINT "Device ="; x; LOOP UNTIL INKEY$ = CHR$(27) 'escape key exit END '' '' |
Device = 2 Device = 2 |
- Note: Mouse events must be within the program screen area. Keyboard presses are registered only when program is in focus.
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...LOOP 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 -1 (true) only when the mouse is moved, scrolled or clicked.
DO...LOOP: device = _DEVICEINPUT ON...GOSUB keyboard, mouse, controller 'must be inside program loop LOOP UNTIL INKEY$ = CHR$(27) END keyboard: PRINT device; "Keyboard"; RETURN mouse: PRINT device; "Mouse "; RETURN controller: PRINT device; "Game control "; RETURN '' '' |
- Note: ON...GOSUB and ON...GOTO events require numerical values to match the order of line labels listed in the event used inside loops.
- _DEVICES, _DEVICE$
- _LASTBUTTON, _LASTAXIS, _LASTWHEEL
- _BUTTON, _AXIS, _WHEEL
- STRIG, STICK
- ON...GOSUB (numerical events)
- Controller Devices
Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page