1. pygame
  2. pygame
  3. pygame


pygame / docs / ref / Joystick.html

<body bgcolor=#dddddd text=#333377 link=#7777bb vlink=#7777bb>

<table border=0 width=100% cellpadding=0 cellspacing=0 bgcolor=#f5f5f5><tr valign=top>
<td rowspan=2><table border=0 cellpadding=5 cellspacing=0 bgcolor=#333377>
<tr height=86 align=left><td valign=middle><font color=#ffffff size=+5>
	<a href=../index.html><font size=+5 color=#ffffff><i><b>
<td valign=middle><tt><font color=#dddddd><br>
</td></tr></table></td><td width=100% align=center valign=middle>

	<a href=http://pygame.seul.org>Home</a> &nbsp;||&nbsp;
	<a href=../index.html>Help Contents</a> &nbsp;||

|| <a href=CD.html>CD</a> || 
<a href=Channel.html>Channel</a> || 
<a href=Font.html>Font</a> || 
<a href=Joystick.html>Joystick</a> || 
<a href=Rect.html>Rect</a> || 
<a href=Sound.html>Sound</a> || 
<a href=Surface.html>Surface</a> ||<br>
|| <a href=pygame.html>pygame</a> || 
<a href=pygame_UserRect.html>UserRect</a> || 
<a href=pygame_cdrom.html>cdrom</a> || 
<a href=pygame_constants.html>constants</a> || 
<a href=pygame_cursors.html>cursors</a> || 
<a href=pygame_display.html>display</a> || 
<a href=pygame_event.html>event</a> ||<br>
|| <a href=pygame_font.html>font</a> || 
<a href=pygame_image.html>image</a> || 
<a href=pygame_joystick.html>joystick</a> || 
<a href=pygame_key.html>key</a> || 
<a href=pygame_mixer.html>mixer</a> || 
<a href=pygame_mixer_music.html>mixer_music</a> || 
<a href=pygame_mouse.html>mouse</a> ||<br>
|| <a href=pygame_surfarray.html>surfarray</a> || 
<a href=pygame_time.html>time</a> || 
<a href=pygame_version.html>version</a> ||<br>

<h2 align=center>Joystick</h2>
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.


<tr><td><a href=#get_axis>get_axis</a></td><td> -
get the position of a joystick axis</td></tr>

<tr><td><a href=#get_ball>get_ball</a></td><td> -
get the movement of a joystick trackball</td></tr>

<tr><td><a href=#get_button>get_button</a></td><td> -
get the position of a joystick button</td></tr>

<tr><td><a href=#get_hat>get_hat</a></td><td> -
get the position of a joystick hat</td></tr>

<tr><td><a href=#get_id>get_id</a></td><td> -
get device id number for joystick</td></tr>

<tr><td><a href=#get_init>get_init</a></td><td> -
check if joystick is initialized</td></tr>

<tr><td><a href=#get_name>get_name</a></td><td> -
query name of joystick drive</td></tr>

<tr><td><a href=#get_numaxes>get_numaxes</a></td><td> -
get number of axes on a joystick</td></tr>

<tr><td><a href=#get_numballs>get_numballs</a></td><td> -
get number of trackballs on a joystick</td></tr>

<tr><td><a href=#get_numballs>get_numballs</a></td><td> -
get number of hats on a joystick</td></tr>

<tr><td><a href=#get_numbuttons>get_numbuttons</a></td><td> -
get number of buttons on a joystick</td></tr>

<tr><td><a href=#init>init</a></td><td> -
initialize a joystick device for use</td></tr>

<tr><td><a href=#quit>quit</a></td><td> -
uninitialize a joystick device for use</td></tr>



<a name=get_axis><font size=+2><b>get_axis
</b></font><br><font size=+1><tt>
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.

<a name=get_ball><font size=+2><b>get_ball
</b></font><br><font size=+1><tt>
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 <u>get_ball()</u>

<a name=get_button><font size=+2><b>get_button
</b></font><br><font size=+1><tt>
Joystick.get_button(button) -> bool
Returns the current state of a joystick button.

<a name=get_hat><font size=+2><b>get_hat
</b></font><br><font size=+1><tt>
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

<a name=get_id><font size=+2><b>get_id
</b></font><br><font size=+1><tt>
Joystick.get_id() -> idnum
Returns the device id number for this Joystick. This is the
same number used in the call to <a href=pygame_joystick.html#Joystick>pygame.joystick.Joystick()</a> to create
the object. The Joystick does not need to be initialized for this
function to work.

<a name=get_init><font size=+2><b>get_init
</b></font><br><font size=+1><tt>
Joystick.get_init() -> bool
Returns a true value if the Joystick is initialized.

<a name=get_name><font size=+2><b>get_name
</b></font><br><font size=+1><tt>
Joystick.get_name(id) -> string
Returns the name of the Joystick device, given by the
system. This function can be called before the Joystick
is initialized.

<a name=get_numaxes><font size=+2><b>get_numaxes
</b></font><br><font size=+1><tt>
Joystick.get_numaxes() -> int
Returns the number of available axes on the Joystick.

<a name=get_numballs><font size=+2><b>get_numballs
</b></font><br><font size=+1><tt>
Joystick.get_numballs() -> int
Returns the number of available trackballs on the Joystick.

<a name=get_numballs><font size=+2><b>get_numballs
</b></font><br><font size=+1><tt>
Joystick.get_numballs() -> int
Returns the number of available directional hats on the Joystick.

<a name=get_numbuttons><font size=+2><b>get_numbuttons
</b></font><br><font size=+1><tt>
Joystick.get_numbuttons() -> int
Returns the number of available buttons on the Joystick.

<a name=init><font size=+2><b>init
</b></font><br><font size=+1><tt>
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.

<a name=quit><font size=+2><b>quit
</b></font><br><font size=+1><tt>
Joystick.quit() -> None
After you are completely finished with a joystick device, you
can use this <a href=pygame.html#quit>quit()</a> 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.