JoyZ# ( [port] )
Parameters
| port (optional) - which joystick to read; 0 is the first stick (default) |
Description
|
Returns the position of the joystick's z-axis as a float from -1 to 1. The z-axis is the third analogue control on a stick. Which physical control that is depends on the hardware: on a flight stick it is usually the throttle lever or the twist of the handle, and on a pad it is often a trigger or the second thumbstick's vertical travel. Games use it for throttle, rudder or zoom. The range works like the other axes: -1 at one end, 0 in the middle and 1 at the other. A throttle that rests at the bottom of its travel reads near one end rather than near zero, so map the value to your own 0-to-1 range instead of assuming a centred stick. Heads up: the current DirectX 12 runtime does not enumerate joysticks - it reports zero attached devices - so JoyZ returns 0.0 on every port, as does an out-of-range port number. Check JoyType before you rely on it and keep a keyboard alternative. If the control you want is not on this axis, the further axes are available as JoyU, JoyV, JoyPitch, JoyYaw and JoyRoll. See also: JoyX, JoyY, JoyZDir, JoyType, JoyDown. |
Example
; JoyZ Example ; ------------ Graphics 640,480,0,2 SetBuffer BackBuffer() While Not KeyDown(1) Cls ; JoyZ returns the stick's z-axis as a float from -1.0 to 1.0 - ; on most pads this is the throttle, twist grip or trigger axis. jz#=JoyZ() If JoyType()=0 Then Text 0,0,"Esc: exit" Text 0,60,"No joystick detected - plug in a gamepad to try this example." Text 0,80,"With one attached, the throttle gauge follows the z-axis." Else Text 0,0,"Move the throttle / twist / trigger axis Esc: exit" End If ; Throttle gauge: -1 at the bottom, +1 at the top Color 90,90,90 Rect 300,100,40,280,False Line 290,240,350,240 ; centre (zero) line h=jz*140 Color 0,200,0 If h>=0 Then Rect 301,240-h,38,h+1,True Else Rect 301,240,38,1-h,True End If Color 255,255,255 Text 0,20,"JoyZ() = "+jz Flip Wend End
Index