This example was built from the getJoystick() example in the manual. I included comments to explain things. As well as a map to each button on the controller.
Code: Select all
' Example code for using getJoystick() with Xbox controllers by Auios
as integer buttons
as single lax, lay
as single rax, ray
as single dpadx, dpady
as single triggers
function getXboxController(ID as long, xbct as xboxController) as integer
return getJoystick(ID, xbct.buttons, xbct.lax, xbct.lay, xbct.triggers, xbct.ray, xbct.rax, , xbct.dpadx, xbct.dpady)
const joystickID = 0
' Check to see if the joystick is okay.
if getJoystick(joystickID) Then
Print "Joystick doesn't exist or joystick error."
Print "Press any key to continue."
screenres 800, 600
dim as XboxController myController
dim as integer result
result = getXboxController(JoystickID, myController)
' If you want to turn your analog input into a straight dpad input you can try this:
' x = cast(integer, x)
' y = cast(integer, y)
print("Result -> " & result)
print("Buttons -> " & myController.buttons)
print("Triggers -> " & myController.triggers)
print("Left analog -> (" & myController.lax & ", " & myController.lay & ")")
print("Right analog -> (" & myController.rax & ", " & myController.ray & ")")
print("DPad -> (" & myController.dpadx & ", " & myController.dpady & ")")
for i as integer = 0 to 31
If (myController.buttons And (1 Shl i)) Then
Print "Button ";i;" pressed. "
Print "Button ";i;" not pressed."
loop until(inkey = chr(27))
' 0 A
' 1 B
' 2 X
' 3 Y
' 4 Left
' 5 Right
' 6 Back
' 7 Start
' 8 Left Analog Button
' 9 Right Analog Button