Controller Devices - mkilgore/QB64pe GitHub Wiki
QB64 supports all kinds of keyboard, mouse, joystick, gamepad, steering wheel and other multi-stick controller input devices.
- In order to read the device controls, the number of input devices MUST first be found using _DEVICES.
- After the device count is determined we can find out the type of device, the device name and the type of controls available using the _DEVICE$(device_number) function. The function returns a STRING containing information about each numbered device.
- "[CONTROLLER][[DEVICENAME] device description][BUTTON][AXIS][WHEEL]"
- _DEVICEINPUT can indicate a used device number or true when a specified device number is active.
- device = _DEVICEINPUT would return 1 for a keyboard event and 2 for a mouse event.
- mouse = _DEVICEINPUT(2) would return -1(true) when the mouse was moved, clicked or scrolled.
Normally the number 1 device, it usually only has [BUTTON] controls. Program window must be in focus to read key activity.
- [KEYBOARD][BUTTON]
-
_LASTBUTTON(1) will normally return 512 buttons.
- _BUTTONCHANGE(number) returns -1 when pressed, 1 when released and 0 when there is no event since the last read.
- _BUTTON(number) returns -1 when a button is pressed and 0 when released.
Normally the number 2 device, a mouse usually has [AXIS], [BUTTON] and [WHEEL] controls. Pointer must be in program screen area.
- [MOUSE][BUTTON][AXIS][WHEEL]
- _LASTAXIS(2) normally returns 2 axis representing the horizontal and vertical mouse, trackball, touch pad or touchscreen axis.
-
_LASTBUTTON(2) will normally return 3 buttons when mouse has a center or scroll wheel button.
- _BUTTONCHANGE(number) returns -1 when pressed, 1 when released and 0 when there is no event since the last read.
-
_BUTTON(number) returns -1 when corresponding button is pressed and 0 when released.
- _BUTTON(1) returns Left button presses like _MOUSEBUTTON(1) and _BUTTONCHANGE(1) returns events.
- _BUTTON(2) returns Center button presses like _MOUSEBUTTON(3) and _BUTTONCHANGE(2) returns events.
- _BUTTON(3) returns Right button presses like _MOUSEBUTTON(2) and _BUTTONCHANGE(3) returns events.
-
_LASTWHEEL(2) will normally return 3 wheels where the first two return relative coordinate movements when set.
-
_WHEEL(number) returns -1 when wheel is scrolled up or forward and 1 when wheel is scrolled down or backward.
- _WHEEL(1) returns relative horizontal pixel moves after _MOUSEMOVEMENTX or Y enables relative mode.
- _WHEEL(2) returns relative vertical pixel moves after _MOUSEMOVEMENTX or Y enables relative mode.
- _WHEEL(3) returns -1 when scroll wheel is moved forward or up and 1 when scrolled backward or down.
-
_WHEEL(number) returns -1 when wheel is scrolled up or forward and 1 when wheel is scrolled down or backward.
NAME][manufacturer may follow in the controller _DEVICE$ string. Devices can be joysticks, game pads or multi-stick.
- [CONTROLLER][[DeviceName]description][BUTTON][AXIS][WHEEL]
- _LASTAXIS(device_number) normally returns dual axis representing the horizontal and vertical axis or view point("top hat").
-
_LASTBUTTON(device_number) will return the number of buttons or triggers a device has.
- _BUTTONCHANGE(number) returns -1 when pressed, 1 when released and 0 when there is no event since the last read.
- _BUTTON(number) returns -1 when button number is pressed and 0 when released.
-
_LASTWHEEL(device_number) will return the number of wheel controls a device has.
- _WHEEL(number) returns -1 when wheel is scrolled up or forward and 1 when wheel is scrolled down or backward.
- Displays all keyboard, mouse and game controller button, axis and wheel control input values when each device is being used.
FOR...NEXT i = 1 TO _DEVICES 'DEVICES MUST be read first!
PRINT STR$(i) + ") " + _DEVICE$(i) + " Buttons:"; _LASTBUTTON(i); ",Axis:"; _LASTAXIS(i); ",Wheel:"; _LASTWHEEL(i)
NEXT
IF...THEN K$ = "Y" THEN dummy = _MOUSEMOVEMENTX 'enable relative mouse movement reads
PRINT
DO...LOOP
x& = _DEVICEINPUT 'determines which device is currently being used
IF...THEN x& = 1 THEN
PRINT "Keyboard: ";
FOR...NEXT b = 1 TO _LASTBUTTON(x&)
bb = _BUTTONCHANGE(b)
IF...THEN bb THEN PRINT b; bb; _BUTTON(b);
NEXT
PRINT
END IF
IF...THEN x& > 1 THEN ' skip keyboard reads
PRINT "Device:"; x&;
FOR...NEXT b = 1 TO _LASTBUTTON(x&)
PRINT _BUTTONCHANGE(b); _BUTTON(b);
NEXT
FOR...NEXT a = 1 TO _LASTAXIS(x&)
PRINT _AXIS(a); 'mouse axis returns -1 to 1 with 0 center screen
NEXT
FOR...NEXT w = 1 TO _LASTWHEEL(x&)
PRINT _WHEEL(w); 'wheels 1 and 2 of mouse return relative pixel moves when enabled
NEXT
PRINT
END IF
LOOP UNTIL INKEY$ = CHR$(27) 'escape key exit
END '' ''
|
- Note: When there is no device control to read, a FOR n = 1 TO 0 loop will not run thus avoiding a control function read error.
- Using _MOUSEMOVEMENTX or Y will hide the mouse cursor and return relative mouse movements with the 1 and 2 _WHEEL controls.
- _DEVICEINPUT, _AXIS, _BUTTON, _BUTTONCHANGE, _WHEEL
- _DEVICES, _DEVICE$, _LASTAXIS, _LASTBUTTON, _LASTWHEEL
- _MOUSEINPUT, _MOUSEX, _MOUSEY, _MOUSEBUTTON, _MOUSEWHEEL
- _MOUSEMOVE, _MOUSEHIDE, _MOUSESHOW
- _MOUSEMOVEMENTX, _MOUSEMOVEMENTY (relative movement)
- STRIG (button), STICK (axis)
Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page