pygame documentation | || Home || Help Contents || || pygame || cdrom || constants || display || draw || event || || font || image || joystick || key || mixer || mixer_music || || mouse || movie || sndarray || surfarray || time || transform || || CD || Channel || Clock || Font || Joystick || Movie || || Rect || Sound || Surface || || color || cursors || sprite ||

## Joystick

The Joystick object represents a joystick device and allows you to access the controls on that joystick. All functions (except get_name() and get_id()) require the Joystick object to be initialized. This is done with the Joystick.init() function.
Joystick control values are only updated during the calls to the event queue. Call pygame.event.pump() if you are not using the event queue for any input handling. Once a joystick object has been initialized, it will start to send joystick events to the input queue.
Be sure to understand there is a difference between the joystick module and the Joystick objects.

get_axis | - get the position of a joystick axis
get_ball | - get the movement of a joystick trackball
get_button | - get the position of a joystick button
get_hat | - get the position of a joystick hat
get_id | - get device id number for joystick
get_init | - check if joystick is initialized
get_name | - query name of joystick drive
get_numaxes | - get number of axes on a joystick
get_numballs | - get number of trackballs on a joystick
get_numbuttons | - get number of buttons on a joystick
get_numhats | - get number of hats on a joystick
init | - initialize a joystick device for use
quit | - uninitialize a joystick device for use

get_axis
`Joystick.get_axis(axis) -> float`

Returns the current position of a joystick axis. The value will range from -1 to 1 with a value of 0 being centered. You may want to take into account some tolerance to handle jitter, and joystick drift may keep the joystick from centering at 0 or using the full range of position values.

get_ball
`Joystick.get_ball(button) -> x, y`

Returns the relative movement of a joystick button. The value is a x, y pair holding the relative movement since the last call to get_ball()

get_button
`Joystick.get_button(button) -> bool`

Returns the current state of a joystick button.

get_hat
`Joystick.get_hat(button) -> x, y`

Returns the current position of a position hat. The position is given as two values representing the X and Y position for the hat. (0, 0) means centered. A value of -1 means left/down a value of one means right/up

get_id
`Joystick.get_id() -> idnum`

Returns the device id number for this Joystick. This is the same number used in the call to pygame.joystick.Joystick() to create the object. The Joystick does not need to be initialized for this function to work.

get_init
`Joystick.get_init() -> bool`

Returns a true value if the Joystick is initialized.

get_name
`Joystick.get_name() -> string`

Returns the name of the Joystick device, given by the system. This function can be called before the Joystick object is initialized.

get_numaxes
`Joystick.get_numaxes() -> int`

Returns the number of available axes on the Joystick.

get_numballs
`Joystick.get_numballs() -> int`

Returns the number of available trackballs on the Joystick.

get_numbuttons
`Joystick.get_numbuttons() -> int`

Returns the number of available buttons on the Joystick.

get_numhats
`Joystick.get_numhats() -> int`

Returns the number of available directional hats on the Joystick.

init
`Joystick.init() -> None`

In order to call most members in the Joystick object, the Joystick must be initialized. You can initialzie the Joystick object at anytime, and it is ok to initialize more than once.

quit
`Joystick.quit() -> None`

After you are completely finished with a joystick device, you can use this quit() function to free access to the drive. This will be cleaned up automatically when the joystick module is. uninitialized. It is safe to call this function on an uninitialized Joystick.