3 <h3 id="TOP">Index</h3>
5 <ul><li><a href="#NAME">NAME</a></li>
6 <li><a href="#CATEGORY">CATEGORY</a></li>
7 <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
8 <li><a href="#METHODS">METHODS</a>
9 <ul><li><a href="#num_joysticks">num_joysticks</a></li>
10 <li><a href="#name">name</a></li>
11 <li><a href="#new">new</a></li>
12 <li><a href="#opened">opened</a></li>
13 <li><a href="#index">index</a></li>
14 <li><a href="#num_axes">num_axes</a></li>
15 <li><a href="#num_balls">num_balls</a></li>
16 <li><a href="#num_hats">num_hats</a></li>
17 <li><a href="#num_buttons">num_buttons</a></li>
18 <li><a href="#update">update</a></li>
19 <li><a href="#get_axis">get_axis</a></li>
20 <li><a href="#get_hat">get_hat</a></li>
21 <li><a href="#get_button">get_button</a></li>
22 <li><a href="#get_ball">get_ball</a></li>
23 <li><a href="#close">close</a></li>
26 <li><a href="#AUTHORS">AUTHORS</a>
31 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
32 <div id="NAME_CONTENT">
33 <p>SDL::Joystick -- SDL Bindings for the Joystick device</p>
36 <h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
37 <div id="CATEGORY_CONTENT">
41 <h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
42 <div id="SYNOPSIS_CONTENT">
46 SDL::init_sub_system(SDL_INIT_JOYSTICK);
48 die('no joystick found') unless(SDL::Joystick::num_joysticks());
50 my $joystick = SDL::Joystick->new(0);
55 <h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
56 <div id="METHODS_CONTENT">
59 <h2 id="num_joysticks">num_joysticks</h2>
60 <div id="num_joysticks_CONTENT">
61 <pre> int SDL::Joystick::num_joysticks( void );
64 <p>Counts and returns available joysticks.</p>
67 <h2 id="name">name</h2>
68 <div id="name_CONTENT">
69 <pre> string SDL::Joystick::name( index );
72 <p>Get the implementation dependent name of joystick. The <code>index</code> parameter refers to the N'th joystick on the system. </p>
73 <pre> my $num_joysticks = SDL::Joystick::num_joysticks();
75 printf("%d joysticks found\n", $num_joysticks);
77 for($i = 0; $i < $num_joysticks; $i++)
79 printf("%s\n", SDL::Joystick::name($i));
86 <div id="new_CONTENT">
87 <pre> object SDL::Joystick->new( index );
90 <p>Opens a joystick for use within SDL. The <code>index</code> refers to the N'th joystick in the system.
91 A joystick must be opened before it can be used.</p>
92 <pre> # Initialize the joystick subsystem
93 SDL::init_sub_system(SDL_INIT_JOYSTICK);
96 if(SDL::Joystick::num_joysticks() > 0)
99 my $joystick = SDL::Joystick->new(0);
103 printf("Opened Joystick 0\n");
104 printf("Name: %s\n", SDL::Joystick::name(0));
105 printf("Number of Axes: %d\n", SDL::Joystick::num_axes($joystick));
106 printf("Number of Buttons: %d\n", SDL::Joystick::num_buttons($joystick));
107 printf("Number of Balls: %d\n", SDL::Joystick::num_balls($joystick));
111 printf("Couldn't open Joystick 0\n");
115 SDL::Joystick::close($joystick) if SDL::Joystick::opened(0);
121 <h2 id="opened">opened</h2>
122 <div id="opened_CONTENT">
123 <pre> int SDL::Joystick::opened( index );
126 <p>Determines whether a joystick has already been opened within the application. <code>index</code> refers to the N'th joystick on the system.</p>
127 <p>Returns 1 if the joystick has been opened, or 0 if it has not.</p>
130 <h2 id="index">index</h2>
131 <div id="index_CONTENT">
132 <pre> int SDL::Joystick::index( object );
135 <p>Returns the <code>index</code> of a given <code>SDL_Joystick</code> structure. See <a href="#new">SDL::Joystick::new</a></p>
138 <h2 id="num_axes">num_axes</h2>
139 <div id="num_axes_CONTENT">
140 <pre> int SDL::Joystick::num_axes( object );
143 <p>Return the number of axes available from a previously opened joystick. See <a href="#new">SDL::Joystick::new</a></p>
146 <h2 id="num_balls">num_balls</h2>
147 <div id="num_balls_CONTENT">
148 <pre> int SDL::Joystick::num_balls( object );
151 <p>Return the number of trackballs available from a previously opened joystick. See <a href="#new">SDL::Joystick::new</a></p>
154 <h2 id="num_hats">num_hats</h2>
155 <div id="num_hats_CONTENT">
156 <pre> int SDL::Joystick::num_hats( object );
159 <p>Gets the number of joystick hats from a previously opened joystick. See <a href="#new">SDL::Joystick::new</a></p>
162 <h2 id="num_buttons">num_buttons</h2>
163 <div id="num_buttons_CONTENT">
164 <pre> int SDL::Joystick::num_buttons( object );
167 <p>Gets the number of joystick buttons from a previously opened joystick. See <a href="#new">SDL::Joystick::new</a></p>
170 <h2 id="update">update</h2>
171 <div id="update_CONTENT">
172 <pre> void SDL::Joystick::update();
175 <p>Updates the state(position, buttons, etc.) of all open joysticks. If joystick events have been enabled
176 with <code>SDL::Joystick::event_state</code> then this is called automatically in the event loop. </p>
179 <h2 id="get_axis">get_axis</h2>
180 <div id="get_axis_CONTENT">
181 <p><code>get_axis</code> returns the current state of the given axis on the given joystick.</p>
182 <p>On most modern joysticks the X axis is usually represented by axis 0 and the Y axis by axis 1.
183 The value returned by <code>get_axis</code> is a signed integer (-32768 to 32767) representing the current position of the axis,
184 it may be necessary to impose certain tolerances on these values to account for jitter.</p>
185 <p><strong>Note</strong>: Some joysticks use axes 2 and 3 for extra buttons. </p>
186 <p>Returns a 16-bit signed integer representing the current position of the axis.</p>
187 <pre> my $joystick = SDL::Joystick->new(0);
189 my $x_move = SDL::Joystick::get_axis($joystick, 0);
190 my $y_move = SDL::Joystick::get_axis($joystick, 1);
195 <h2 id="get_hat">get_hat</h2>
196 <div id="get_hat_CONTENT">
197 <pre> int SDL::Joystick::get_hat( object, int );
200 <p><code>get_hat</code> returns the current state of the given <code>hat</code> on the given <code>joystick</code>. </p>
201 <p>The current state is returned which is an OR'd combination of one or more of the following:</p>
203 <li><code>SDL_HAT_CENTERED</code> </li>
204 <li><code>SDL_HAT_UP</code> </li>
205 <li><code>SDL_HAT_RIGHT</code> </li>
206 <li><code>SDL_HAT_DOWN</code> </li>
207 <li><code>SDL_HAT_LEFT</code> </li>
208 <li><code>SDL_HAT_RIGHTUP</code> </li>
209 <li><code>SDL_HAT_RIGHTDOWN</code> </li>
210 <li><code>SDL_HAT_LEFTUP</code> </li>
211 <li><code>SDL_HAT_LEFTDOWN</code></li>
214 <pre> my $joystick = SDL::Joystick->new(0);
216 my $position = SDL::Joystick::get_hat($joystick, 0);
218 print("hat is in position UP\n") if $position & SDL_HAT_UP;
223 <h2 id="get_button">get_button</h2>
224 <div id="get_button_CONTENT">
225 <pre> int SDL::Joystick::get_button( object, int );
228 <p><code>get_button</code> returns the current state of the given button on the given joystick.</p>
229 <p>Returns 1 if the button is pressed. Otherwise, 0. </p>
230 <pre> my $joystick = SDL::Joystick->new(0);
232 my $num_buttons = SDL::Joystick::num_buttons($joystick);
234 for(my $i = 0; $i < $num_buttons; $i++)
236 printf("button %d is %s\n", $i, SDL::Joystick::get_button($joystick, $i) ? 'pressed' : 'not pressed');
239 SDL::Joystick::close($joystick) if SDL::Joystick::opened(0);
244 <h2 id="get_ball">get_ball</h2>
245 <div id="get_ball_CONTENT">
246 <pre> int SDL::Joystick::get_ball(SDL_Joystick $joystick, int $ball, int $dx, int $dy);
249 <p>Get the ball axis change.</p>
250 <p>Trackballs can only return relative motion since the last call to SDL::Joystick::get_ball, these motion deltas are placed into <code>dx</code> and <code>dy</code>.</p>
251 <p>Returns 0 on success or -1 on failure</p>
252 <pre> my $delta_x = 0;
254 my $joystick = SDL::Joystick->new(0);
256 SDL::Joystick::update();
258 printf("TrackBall Read Error!\n") if(SDL::JoystickGetBall($joystick, 0, $delta_x, $delta_y) == -1);
259 printf("Trackball Delta- X:%d, Y:%d\n", delta_x, delta_y);
264 <h2 id="close">close</h2>
265 <div id="close_CONTENT">
266 <pre> void SDL::Joystick::close( object );
269 <p>Closes a previously opened joystick. See <a href="#new">SDL::Joystick::new</a></p>
270 <pre> SDL::Joystick::close($joystick) if SDL::Joystick::opened(0);
275 <h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
276 <div id="AUTHORS_CONTENT">
277 <p>See <a href="/SDL.html#AUTHORS">/SDL.html#AUTHORS</a>.</p>