QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The _DEVICE$ function returns a STRING value holding the controller type, name and input types of the input devices on a computer.


device$ = _DEVICE$(device_number)


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 "Buttons:"; _LASTBUTTON(i); "Axis:"; _LASTAXIS(i); "Wheels:"; _LASTWHEEL(i)

Number of input devices found = 3
Buttons: 512 Axis: 0 Wheels: 0
Buttons: 3 Axis: 2 Wheels: 3
[CONTROLLER][NAME][Microsoft Sidewinder Precision Pro (USB)](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.

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
PRINT buttons; "mouse buttons available" 

See Also