QB64.com

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 STICK function returns the directional axis coordinate move of game port (&H201) joystick or USB controller devices.

Syntax

coordinate_move% = STICK(direction%)

QB64 Syntax

coordinate_move% = STICK(direction%[, axis_number%])

Description


**STICK(0) returns the column coordinate of device 1. Enables reads of the other STICK values.**
**STICK(1) returns row coordinate of device 1.**
STICK(2) returns column coordinate of device 2. (second joystick if used)
STICK(3) returns row coordinate of device 2 if used. (QBasic maximum was 2 controllers)
**STICK(4) returns column coordinate of device 3. (other joysticks if used in QB64 only!)**
**STICK(5) returns row coordinate of device 3 if used.**

Example(s)

Displays the input from 3 joysticks, all with dual sticks and 3 buttons.


DO: _LIMIT 10

  LOCATE 1, 1
  PRINT "JOY1: STICK"; STICK(0); STICK(1); STICK(0, 2); STICK(1, 2);_ 
  "STRIG"; STRIG(0); STRIG(1); STRIG(4); STRIG(5); STRIG(8); STRIG(9)

  PRINT "JOY2: STICK"; STICK(2); STICK(3); STICK(2, 2); STICK(3, 2);_ 
  "STRIG"; STRIG(2); STRIG(3); STRIG(6); STRIG(7); STRIG(10); STRIG(11)

  PRINT "JOY3: STICK"; STICK(4); STICK(5); STICK(4, 2); STICK(5, 2);_ 
  "STRIG"; STRIG(0, 3); STRIG(1, 3); STRIG(4, 3); STRIG(5, 3); STRIG(8, 3); STRIG(9, 3)
    
LOOP UNTIL INKEY$ > "" 

Explanation: Notice the extra QB64 only parameters used to cater for the 2nd stick and the buttons of the 3rd joystick.

Displays the Sidewinder Precision Pro Stick, Slider, Z Axis, and Hat Point of View.


SCREEN 12
d = _DEVICES
PRINT "Number of input devices found ="; d
FOR i = 1 TO d
  PRINT _DEVICE$(i)
  buttons = _LASTBUTTON(i)
  PRINT "Buttons:"; buttons
NEXT

DO: _LIMIT 50
  LOCATE 10, 1
  PRINT "   X    Main    Y          Slider         Z-axis           POV"
  PRINT STICK(0, 1), STICK(1, 1), STICK(0, 2), STICK(1, 2), STICK(0, 3); STICK(1, 3); "   "
  PRINT "                   Buttons"
  FOR i = 0 TO 4 * buttons - 1 STEP 4
    PRINT STRIG(i); STRIG(i + 1); CHR$(219);
  NEXT
  PRINT
LOOP UNTIL INKEY$ <> "" 

Explanation: Each axis on the first controller found is either STICK(0, n) or STICK(1, n) with n increasing when necessary.


Number of input devices found = 3
[KEYBOARD][BUTTON]]
Buttons: 512
[MOUSE][BUTTON][AXIS][WHEEL]
Buttons: 3
[CONTROLLER][NAME][Microsoft Sidewinder Precision Pro (USB)](NAME][Microsoft-Sidewinder-Precision-Pro-(USB))[BUTTON][AXIS]
Buttons: 9

  X    Main     Y          Slider         Z-axis           POV
 127           127           254           127           127  127
                      Buttons
-0 -1 █ 0  0 █ 0  0 █ 0  0 █ 0  0 █ 0  0 █ 0  0 █ 0  0 █ 0  0 █

Note: A Sidewinder Precision Pro requires that pins 2 and 7(blue and purple) be connected together for digital USB recognition.

See Also