This section describes functions which read the state of a joystick. Currently, these functions are available on Windows, Mac and Linux computers.
Get the state of the joystick buttons.
b = joystickbuttons(i)
joystickbuttons(i) gives the state of the buttons of the joystick i. Each buttons corresponds to a bit of the result; for instance, if the result of joystickbuttons(1) is 4, the 3rd button of the first joystick is pressed (4 is 2^(3-1), while all other buttons are released.
List of joysticks connected to the computer.
l = joysticklist
joysticklist gives the list of the joysticks connected to the computer. Each element is a string which contains the name of the joystick. Empty string represent joystick not connected. Joysticks are listed in the same order as the index of the joystick used as input argument of joystickbuttons and joystickpos.
Get the state of the joystick buttons.
pos = joystickpos(i)
joystickpos(i) gives the position of the joystick i as a vector whose elements are normalized between -1 and 1. For a standard joystick, the first component is between -1 for left and 1 for right; the second component, between -1 for forward (joystick pushed) and 1 for backward (pulled); and additional components depend on the joystick and the driver.