|
pygame.joystick.init | initialize the joystick module |
pygame.joystick.quit | uninitialize the joystick module |
pygame.joystick.get_init | true if the joystick module is initialized |
pygame.joystick.get_count | number of joysticks on the system |
pygame.joystick.Joystick | create a new Joystick object |
The joystick module manages the joystick devices on a computer. This module needs to be initialized before it can do anything. Each Joystick object you create represents a joystick device and must also be initialized individually before it can do most things.
Initialize the joystick module. This will scan the system for all joystick devices. The module must be initialized before any other functions will work. This automatically happens when you call pygame.init.
It is safe to call this function more than once.
Uninitialize the joystick module. After you call this any existing joystick objects will no longer work.
It is safe to call this function more than once.
Test if the joystick module is initialized or not.
Return the number of joystick devices on the system. When you create Joystick objects you need to pass an integer id that must be lower than this count. The count will be 0 if there are no joysticks on the system.
Joystick.init | initialize the Joystick |
Joystick.quit | uninitialize the Joystick |
Joystick.get_init | check if the Joystick is initialized |
Joystick.get_id | get the Joystick id |
Joystick.get_name | get the Joystick system name |
Joystick.get_numaxes | get the number of axes on a Joystick |
Joystick.get_axis | get the current position of an axis |
Joystick.get_numballs | get the number of trackballs on a Joystick |
Joystick.get_ball | get the relative position of a trackball |
Joystick.get_numbuttons | get the number of buttons on a Joystick |
Joystick.get_button | get the current button state |
Joystick.get_numhats | get the number of hat controls on a Joystick |
Joystick.get_hat | get the position of a joystick hat |
Create a new joystick to access the given joystick. The id argument must be a value from 0 to less than pygame.joystick.get_count.
To access most of the Joystick methods, you'll need to init() the Joystick. This is separate from making sure the joystick module is initialized. When multiple Joysticks objects are created for the same joystick device, the state and values for those Joystick objects will be shared.
The Joystick object allows you to get information about the types of controls on a joystick device. Once the device is initialized the Pygame event queue will start receiving events about its input.
You can call the Joystick.get_name and Joystick.get_id functions without initializing the Joystick object.
The Joystick must be initialized to get most of the information about the controls. While the Joystick is initialized the Pygame event queue will receive events from the Joystick input.
It is safe to call this more than once.
This will unitialize a Joystick. After this the Pygame event queue will no longer receive events from the device.
It is safe to call this more than once.
Returns True when the Joystick object is initialized.
Returns the integer id that represents this device. This is the same value that was used to initialize the Joystick object. This method can safely be called while the Joystick is not initialized.
Returns the system name for this joystick device. It is unknown what name the system will give to the Joystick, but it should be a unique name that identifies the device. This method can safely be called while the Joystick is not initialized.
Returns the number of input axes are on a Joystick. There will usually be two for the position. Controls like rudders and throttles are treated as additional axes.
The pygame.JOYAXISMOTION events will be in the range from -1.0 to 1.0. A value of 0.0 means the axis is centered. Gamepad devices will usually be -1, 0, or 1 with no values in between. Older analog joystick axis will not always use the full -1 to 1 range, and the centered value will be some area around 0. Analog joysticks usually have a bit of noise in their axis, which will generate a lot of rapid small motion events.
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.
Returns the number of trackball devices on a Joystick. These devices work similar to a mouse but they have not absolute position, only relative amounts of movement.
the pygame.JOYBALLMOTION event will be sent the the trackball is rolled. It will report the amount of movement on the trackball.
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.
Returns the number of pushable buttons on the joystick. These buttons have a boolean on or off state. There is no way to know the current state of a button, you can only watch for its events on the queue.
Buttons generate a pygame.JOYBUTTONDOWN and pygame.JOYBUTTONUP event when they are pressed and released.
Returns the current state of a joystick button.
Returns the number of joystick hats on a Joystick. Hat devices are like miniature digital joysticks on a joystick. The hats are digital with have two axis of input.
The pygame.JOYHATMOTION events are generated when the hat changes position. The position attribute for the event contains a pair of values that are either -1, 0, or 1. A position of (0, 0) means the hat is centered.
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 1 means right/up.