mirror of
https://github.com/QB64Official/qb64.git
synced 2024-09-28 11:17:47 +00:00
98 lines
4.6 KiB
Text
98 lines
4.6 KiB
Text
The '''STICK''' function returns the directional axis coordinate move of game port (&H201) joystick or USB controller devices.
|
|
|
|
|
|
{{PageSyntax}}
|
|
:: coordinate_move% = STICK(direction%)
|
|
|
|
|
|
== QB64 Syntax ==
|
|
:: coordinate_move% = STICK(''direction%''[, ''axis_number%''])
|
|
|
|
|
|
''Description:''
|
|
* '''QB64''' allows any number of coordinate pairs for more than two game device controllers. STICK will not read a mouse axis.
|
|
* ''axis_number'' can be used as the next axis parameter for controllers with multiple axis using the SAME ''directional'' parameters.
|
|
* The ''axis_number'' 1 can be omitted for the main stick column and row parameter reads.
|
|
* Point of view "hats" also have 2 axis. Slide, turn or twist controls have one. The device determines the order of the axis.
|
|
* Returns coordinate values from 1 to 254. QBasic only returned values from 1 to 200.
|
|
* STICK(0) is required to get values from the other STICK functions. Always read it first!
|
|
{{WhiteStart}}'''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.'''
|
|
{{WhiteEnd}}
|
|
* '''QB64''' allows more joysticks by extending the numbers in pairs like device 3 above. EX: STICK(6): STICK(7) 'device 4
|
|
* '''QB64''' allows a dual stick to be read using the same first parameters and 2 as the second parameter. EX: STICK(0, 2)
|
|
* '''There will not be an error if you try to read too many device axis or buttons!'''
|
|
|
|
|
|
''Example 1:'' Displays the input from 3 joysticks, all with dual sticks and 3 buttons.
|
|
{{CodeStart}} '' ''
|
|
{{Cl|DO}}: {{Cl|_LIMIT}} 10
|
|
|
|
{{Cl|LOCATE}} 1, 1
|
|
{{Cl|PRINT}} "JOY1: {{Cl|STICK}}"; {{Cl|STICK}}(0); {{Cl|STICK}}(1); {{Cl|STICK}}(0, 2); {{Cl|STICK}}(1, 2);_
|
|
"STRIG"; {{Cl|STRIG}}(0); {{Cl|STRIG}}(1); {{Cl|STRIG}}(4); {{Cl|STRIG}}(5); {{Cl|STRIG}}(8); {{Cl|STRIG}}(9)
|
|
|
|
{{Cl|PRINT}} "JOY2: {{Cl|STICK}}"; {{Cl|STICK}}(2); {{Cl|STICK}}(3); {{Cl|STICK}}(2, 2); {{Cl|STICK}}(3, 2);_
|
|
"STRIG"; {{Cl|STRIG}}(2); {{Cl|STRIG}}(3); {{Cl|STRIG}}(6); {{Cl|STRIG}}(7); {{Cl|STRIG}}(10); {{Cl|STRIG}}(11)
|
|
|
|
{{Cl|PRINT}} "JOY3: {{Cl|STICK}}"; {{Cl|STICK}}(4); {{Cl|STICK}}(5); {{Cl|STICK}}(4, 2); {{Cl|STICK}}(5, 2);_
|
|
"STRIG"; {{Cl|STRIG}}(0, 3); {{Cl|STRIG}}(1, 3); {{Cl|STRIG}}(4, 3); {{Cl|STRIG}}(5, 3); {{Cl|STRIG}}(8, 3); {{Cl|STRIG}}(9, 3)
|
|
|
|
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} > "" '' ''
|
|
{{CodeEnd}}
|
|
:''Explanation:'' Notice the extra '''QB64 only''' parameters used to cater for the 2nd stick and the buttons of the 3rd joystick.
|
|
|
|
|
|
''Example 2:'' Displays the Sidewinder Precision Pro Stick, Slider, Z Axis, and Hat Point of View.
|
|
{{CodeStart}} '' ''
|
|
{{Cl|SCREEN}} 12
|
|
d = {{Cl|_DEVICES}}
|
|
{{Cl|PRINT}} "Number of input devices found ="; d
|
|
{{Cl|FOR...NEXT|FOR}} i = 1 {{Cl|TO}} d
|
|
{{Cl|PRINT}} {{Cl|_DEVICE$}}(i)
|
|
buttons = {{Cl|_LASTBUTTON}}(i)
|
|
{{Cl|PRINT}} "Buttons:"; buttons
|
|
{{Cl|NEXT}}
|
|
|
|
DO: {{Cl|_LIMIT}} 50
|
|
{{Cl|LOCATE}} 10, 1
|
|
{{Cl|PRINT}} " X Main Y Slider Z-axis POV"
|
|
{{Cl|PRINT}} {{Cl|STICK}}(0, 1), {{Cl|STICK}}(1, 1), {{Cl|STICK}}(0, 2), {{Cl|STICK}}(1, 2), {{Cl|STICK}}(0, 3); {{Cl|STICK}}(1, 3); " "
|
|
{{Cl|PRINT}} " Buttons"
|
|
{{Cl|FOR...NEXT|FOR}} i = 0 {{Cl|TO}} 4 * buttons - 1 {{Cl|STEP}} 4
|
|
{{Cl|PRINT}} {{Cl|STRIG}}(i); {{Cl|STRIG}}(i + 1); {{Cl|CHR$}}(219);
|
|
{{Cl|NEXT}}
|
|
{{Cl|PRINT}}
|
|
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} <> "" '' ''
|
|
{{CodeEnd}}
|
|
: ''Explanation:'' Each axis on the first controller found is either STICK(0, n) or STICK(1, n) with n increasing when necessary.
|
|
{{OutputStart}}
|
|
Number of input devices found = 3
|
|
[KEYBOARD][BUTTON]]
|
|
Buttons: 512
|
|
[MOUSE][BUTTON][AXIS][WHEEL]
|
|
Buttons: 3
|
|
[CONTROLLER][[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 █
|
|
{{OutputEnd}}
|
|
: ''Note:'' A Sidewinder Precision Pro requires that pins 2 and 7 (blue and purple) be connected together for digital USB recognition.
|
|
|
|
|
|
''See also:''
|
|
* [[STRIG]] {{text|(function)}}
|
|
* [[ON STRIG(n)]]
|
|
* [[_DEVICES]], [[_DEVICE$]], [[_LASTBUTTON]]
|
|
* [http://en.wikipedia.org/wiki/Analog_stick Single and Dual Stick Controllers]
|
|
|
|
|
|
{{PageNavigation}}
|