| port (optional) - which joystick to ask about; 0 is the first stick (default) |
|
Reports what kind of joystick is attached to a port. The answer is one of three values: 0: no joystick on that port 1: digital joystick or pad 2: analogue joystick or pad It is the command you call once at startup to decide how to read the stick. A 1 means the directions are on or off, so JoyXDir and JoyYDir tell you everything. A 2 means there is a real analogue range to read with JoyX and JoyY, so you can support gentle steering as well as full lock. Heads up: the current DirectX 12 runtime does not enumerate joysticks at all - it reports zero attached devices - so JoyType returns 0 on every port and the rest of the Joy commands hand back their neutral values. The commands are still there so existing code compiles and runs unchanged, but treat a joystick as optional and always give the player a keyboard or mouse route to everything. That makes JoyType the right guard to write around joystick code: check it once, and if it is 0 skip the joystick path entirely rather than waiting on a stick that will never answer. See also: JoyDown, JoyHit, JoyX, JoyXDir, GetJoy, KeyDown. |
; JoyType Example
; ---------------
Graphics 640,480,0,2
SetBuffer BackBuffer()
While Not KeyDown(1)
Cls
; JoyType reports what is plugged in: 0=none, 1=digital, 2=analog.
; The example polls it every frame.
jt=JoyType()
Select jt
Case 0
desc$="no joystick detected - plug in a gamepad!"
Case 1
desc$="digital joystick attached"
Case 2
desc$="analog joystick attached"
End Select
Text 0,0,"Try plugging a joystick in or out Esc: exit"
Text 0,20,"JoyType() = "+jt+" ("+desc$+")"
If jt>0 Then
; With a stick attached, prove it works with live axis readouts
Text 0,60,"Stick x-axis JoyX(): "+JoyX()
Text 0,80,"Stick y-axis JoyY(): "+JoyY()
End If
Flip
Wend
End