JoyDown ( button[,port] )
Parameters
|
button - number of the joystick button to test, counting from 1 port (optional) - which joystick to read; 0 is the first stick (default) |
Description
|
Returns True while the given joystick button is being held down. It is the pad equivalent of KeyDown: 1 while the button is held, 0 while it is not. Use it for anything continuous - holding a trigger to keep firing, holding a shoulder button to brake, holding a face button to charge a shot. Each button is tested on its own, so a combination is just two JoyDown calls. For actions that should happen once per press - jumping, confirming a menu item, changing weapon - use JoyHit instead, or the whole thing repeats every frame the button stays down. Reading state does not consume it, so several parts of your code can test the same button in the same frame and all of them see it. Heads up: the current DirectX 12 runtime does not enumerate joysticks - it reports zero attached devices - so JoyDown returns 0 on every port and button. A port number outside the range of attached sticks returns 0 too rather than raising an error. Check JoyType once at startup and keep a keyboard route to everything the player must be able to do. See also: JoyHit, GetJoy, JoyType, FlushJoy, KeyDown, MouseDown. |
Example
; JoyDown Example ; --------------- Graphics 640,480,0,2 SetBuffer BackBuffer() While Not KeyDown(1) Cls 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 lights below follow the held buttons." Else Text 0,0,"Hold joystick buttons 1-8 Esc: exit" End If ; JoyDown returns 1 while the numbered button is HELD - test ; each button separately. ; (Compare JoyHit, which reports each press only once.) held$="" For b=1 To 8 If JoyDown(b) Then Color 255,220,0 Oval 60+(b-1)*70,200,50,50,True held$=held$+b+" " Else Color 90,90,90 Oval 60+(b-1)*70,200,50,50,False End If Color 255,255,255 Text 85+(b-1)*70,270,Str(b),True Next Text 0,20,"Buttons held (JoyDown): "+held$ Flip Wend End
Index