From QB64 Wiki
Jump to navigation Jump to search

The _LASTBUTTON function returns the number of buttons a specified INPUT device on your computer has.


buttonCount% = __LASTBUTTON(deviceNumber)

  • Returns the number of buttons that can be read on a specified device number within the number of _DEVICES found.
  • A valid number can be sent to the _BUTTON or _BUTTONCHANGE function to find any button events.
  • The specific device name and functions can be found by the _DEVICE$ function string.
  • The devices are listed in a numerical order determined by the OS and can be read by the DEVICE$ function.
  • The _DEVICES function must be read before using _LASTBUTTON or an "Illegal Function Call" error will occur.
  • Devices include keyboard (reported as 1), mouse (reported as 2), joysticks, game pads and multiple stick game controllers.


Example: Checking for the system's input devices.

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) NEXT

Number of input devices found = 2 [KEYBOARD][BUTTON] Buttons: 512 [MOUSE][BUTTON][AXIS][WHEEL] Buttons: 3

Note: The STRIG/STICK commands won't read from the keyboard or mouse device the above example lists.

See also

Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page