Merge branch 'master' of git.shadowcat.co.uk:SDL-Site
[sdlgit/SDL-Site.git] / pages / SDL-Events.html-inc
CommitLineData
162a0989 1<div class="pod">
2<!-- INDEX START -->
3<h3 id="TOP">Index</h3>
4
60f74f6f 5<ul><li><a href="#NAME">NAME</a>
6<ul><li><a href="#CATEGORY">CATEGORY</a></li>
7</ul>
8</li>
162a0989 9<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
4e623c18 10<li><a href="#CONSTANTS">CONSTANTS</a></li>
162a0989 11<li><a href="#METHODS">METHODS</a>
12<ul><li><a href="#pump_events">pump_events</a></li>
13<li><a href="#peep_events_event_num_events_action_">peep_events (event, num_events, action, mask) </a>
14<ul><li><a href="#RETURN">RETURN</a></li>
15</ul>
16</li>
17<li><a href="#poll_event_event">poll_event($event)</a>
18<ul><li><a href="#RETURN-2">RETURN</a></li>
19</ul>
20</li>
21<li><a href="#push_event_event">push_event($event)</a>
22<ul><li><a href="#RETURN-3">RETURN</a></li>
23</ul>
24</li>
25<li><a href="#wait_event_event">wait_event($event)</a>
26<ul><li><a href="#RETURN-4">RETURN</a></li>
27</ul>
28</li>
55bbf7a2 29<li><a href="#set_event_filter">set_event_filter</a>
30<ul><li><a href="#PARAMETER">PARAMETER</a></li>
31</ul>
32</li>
cf23a5da 33<li><a href="#get_key_state">get_key_state</a></li>
55bbf7a2 34<li><a href="#get_mod_state">get_mod_state</a>
35<ul><li><a href="#MOD_VALUES">MOD VALUES</a></li>
36</ul>
37</li>
cf23a5da 38<li><a href="#set_mod_state">set_mod_state</a></li>
55bbf7a2 39<li><a href="#event_state">event_state </a>
40<ul><li><a href="#STATES">STATES</a></li>
41</ul>
42</li>
cf23a5da 43<li><a href="#get_key_name">get_key_name</a></li>
44<li><a href="#enable_unicode">enable_unicode </a></li>
45<li><a href="#enable_key_repeat">enable_key_repeat </a></li>
46<li><a href="#get_mouse_state">get_mouse_state </a></li>
47<li><a href="#get_relative_mouse_state">get_relative_mouse_state </a></li>
48<li><a href="#get_app_state">get_app_state </a></li>
49<li><a href="#joystick_event_state">joystick_event_state </a></li>
162a0989 50</ul>
51</li>
c7e8d3c6 52<li><a href="#SEE_ALSO">SEE ALSO</a></li>
53<li><a href="#AUTHORS">AUTHORS</a>
162a0989 54</li>
55</ul><hr />
56<!-- INDEX END -->
57
58<h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
59<div id="NAME_CONTENT">
60<p>SDL::Events - Bindings to the Events Category in SDL API</p>
61
62</div>
60f74f6f 63<h2 id="CATEGORY">CATEGORY</h2>
64<div id="CATEGORY_CONTENT">
65<p>Core, Events</p>
66
67</div>
162a0989 68<h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
69<div id="SYNOPSIS_CONTENT">
55bbf7a2 70<p>Most likely you just want to know how to get events for you app.</p>
4e623c18 71<pre> use SDL ':init';
162a0989 72 use SDL::Event;
4e623c18 73 use SDL::Events ':all';
55bbf7a2 74
75 SDL::init(SDL_INIT_VIDEO); # Event can only be grabbed in the same thread as this
162a0989 76
77 ...
78
79 my $event = SDL::Event-&gt;new(); # notices 'Event' ne 'Events'
80
81 while( 1 )
1dbe1697 82 {
83 SDL::Events::pump_events();
84 while( SDL::Events::poll_event($event) )
85 {
86 #check by event type
87 on_active() if $event-&gt;type == SDL_ACTIVEEVENT;
88 ...
89 }
90 }
162a0989 91
92</pre>
93
94</div>
4e623c18 95<h1 id="CONSTANTS">CONSTANTS</h1><p><a href="#TOP" class="toplink">Top</a></p>
96<div id="CONSTANTS_CONTENT">
3549ee6a 97<p>The constants are exported by default. You can avoid this by doing:</p>
98<pre> use SDL::Events ();
162a0989 99
4e623c18 100</pre>
3549ee6a 101<p>and access them directly:</p>
4e623c18 102<pre> SDL::Events::SDL_ACTIVEEVENT;
103
104</pre>
105<p>or by choosing the export tags below:</p>
106<p>Export tag: ':type'</p>
107<pre> SDL_ACTIVEEVENT
108 SDL_KEYDOWN
109 SDL_KEYUP
110 SDL_MOUSEMOTION
111 SDL_MOUSEBUTTONDOWN
112 SDL_MOUSEBUTTONUP
113 SDL_JOYAXISMOTION
114 SDL_JOYBALLMOTION
115 SDL_JOYHATMOTION
116 SDL_JOYBUTTONDOWN
117 SDL_JOYBUTTONUP
118 SDL_QUIT
119 SDL_SYSWMEVENT
120 SDL_VIDEORESIZE
121 SDL_VIDEOEXPOSE
122 SDL_USEREVENT
123 SDL_NUMEVENTS
124
125</pre>
126<p>Export tag: ':mask'</p>
127<pre> SDL_EVENTMASK
128 SDL_ACTIVEEVENTMASK
129 SDL_KEYDOWNMASK
130 SDL_KEYUPMASK
131 SDL_KEYEVENTMASK
132 SDL_MOUSEMOTIONMASK
133 SDL_MOUSEBUTTONDOWNMASK
134 SDL_MOUSEBUTTONUPMASK
135 SDL_MOUSEEVENTMASK
136 SDL_JOYAXISMOTIONMASK
137 SDL_JOYBALLMOTIONMASK
138 SDL_JOYHATMOTIONMASK
139 SDL_JOYBUTTONDOWNMASK
140 SDL_JOYBUTTONUPMASK
141 SDL_JOYEVENTMASK
142 SDL_VIDEORESIZEMASK
143 SDL_VIDEOEXPOSEMASK
144 SDL_QUITMASK
145 SDL_SYSWMEVENTMASK
146 SDL_ALLEVENTS
147
148</pre>
149<p>Export tag: ':action'</p>
150<pre> SDL_ADDEVENT
151 SDL_PEEKEVENT
152 SDL_GETEVENT
153
154</pre>
155<p>Export tag: ':state'</p>
156<pre> SDL_QUERY
157 SDL_IGNORE
158 SDL_DISABLE / SDL_ENABLE
159 SDL_RELEASED / SDL_PRESSED
162a0989 160
4e623c18 161</pre>
162<p>Export tag: ':hat'</p>
163<pre> SDL_HAT_CENTERED
164 SDL_HAT_UP / SDL_HAT_RIGHT / SDL_HAT_DOWN / SDL_HAT_LEFT
165 SDL_HAT_RIGHTUP / SDL_HAT_RIGHTDOWN / SDL_HAT_LEFTUP / SDL_HAT_LEFTDOWN
162a0989 166
4e623c18 167</pre>
168<p>Export tag: ':app'</p>
169<pre> SDL_APPMOUSEFOCUS
170 SDL_APPINPUTFOCUS
171 SDL_APPACTIVE
162a0989 172
4e623c18 173</pre>
174<p>Export tag: ':button'</p>
175<pre> SDL_BUTTON
176 SDL_BUTTON_LEFT / SDL_BUTTON_MIDDLE / SDL_BUTTON_RIGHT
177 SDL_BUTTON_WHEELUP / SDL_BUTTON_WHEELDOWN
178 SDL_BUTTON_X1 / SDL_BUTTON_X2
179 SDL_BUTTON_LMASK / SDL_BUTTON_MMASK / SDL_BUTTON_RMASK
180 SDL_BUTTON_X1MASK / SDL_BUTTON_X2MASK
181
182</pre>
183<p>Export tag: ':keysym'</p>
184<pre> SDLK_UNKNOWN
185 SDLK_FIRST
186 SDLK_BACKSPACE
187 SDLK_TAB
188 SDLK_CLEAR
189 SDLK_RETURN
190 SDLK_PAUSE
191 SDLK_ESCAPE
192 SDLK_SPACE
193 SDLK_EXCLAIM
194 SDLK_QUOTEDBL
195 SDLK_HASH
196 SDLK_DOLLAR
197 SDLK_AMPERSAND
198 SDLK_QUOTE
199 SDLK_LEFTPAREN / SDLK_RIGHTPAREN
200 SDLK_ASTERISK
201 SDLK_PLUS / SDLK_MINUS
202 SDLK_COMMA
203 SDLK_PERIOD
204 SDLK_0 .. SDLK_9
205 SDLK_COLON
206 SDLK_SEMICOLON
207 SDLK_LESS / SDLK_GREATER
208 SDLK_EQUALS
209 SDLK_QUESTION
210 SDLK_AT
211 SDLK_LEFTBRACKET / SDLK_RIGHTBRACKET
212 SDLK_SLASH / SDLK_BACKSLASH
213 SDLK_CARET
214 SDLK_UNDERSCORE
215 SDLK_BACKQUOTE
216 SDLK_a .. SDLK_z
217 SDLK_DELETE
218 SDLK_WORLD_0 .. SDLK_WORLD_95
219 SDLK_KP0 .. SDLK_KP9
220 SDLK_KP_PERIOD
221 SDLK_KP_DIVIDE / SDLK_KP_MULTIPLY
222 SDLK_KP_MINUS / SDLK_KP_PLUS
223 SDLK_KP_ENTER
224 SDLK_KP_EQUALS
225 SDLK_UP / SDLK_DOWN / SDLK_RIGHT / SDLK_LEFT
226 SDLK_INSERT
227 SDLK_HOME / SDLK_END
228 SDLK_PAGEUP / SDLK_PAGEDOWN
229 SDLK_F1 .. SDLK_F15
230 SDLK_NUMLOCK / SDLK_CAPSLOCK / SDLK_SCROLLOCK
231 SDLK_RSHIFT / SDLK_LSHIFT
232 SDLK_RCTRL / SDLK_LCTRL
233 SDLK_RALT / SDLK_LALT
234 SDLK_RMETA / SDLK_LMETA
235 SDLK_LSUPER / SDLK_RSUPER
236 SDLK_MODE
237 SDLK_COMPOSE
238 SDLK_HELP
239 SDLK_PRINT
240 SDLK_SYSREQ
241 SDLK_BREAK
242 SDLK_MENU
243 SDLK_POWER
244 SDLK_EURO
245 SDLK_UNDO
246
247</pre>
248<p>Export tag ':keymod'</p>
249<pre> KMOD_NONE
250 KMOD_LSHIFT / KMOD_RSHIFT / KMOD_SHIFT
251 KMOD_LCTRL / KMOD_RCTRL / KMOD_CTRL
252 KMOD_LALT / KMOD_RALT / KMOD_ALT
253 KMOD_LMETA / KMOD_RMETA / KMOD_META
254 KMOD_NUM
255 KMOD_CAPS
256 KMOD_MODE
257 KMOD_RESERVED
258
259</pre>
162a0989 260
261</div>
262<h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
263<div id="METHODS_CONTENT">
264
265</div>
266<h2 id="pump_events">pump_events</h2>
267<div id="pump_events_CONTENT">
268<p>Pumps the event loop, gathering events from the input devices.</p>
269<pre> pump_events();
270
271</pre>
1dbe1697 272<p>pump_events gathers all the pending input information from devices and places it on the event queue. Without calls to pump_events no events would
273ever be placed on the queue.
274Often the need for calls to pump_events is hidden from the user since <a href="http://search.cpan.org/perldoc?">http://search.cpan.org/perldoc?</a> and <a href="http://search.cpan.org/perldoc?">http://search.cpan.org/perldoc?</a> implicitly call pump_events.
162a0989 275However, if you are not polling or waiting for events (e.g. you are filtering them), then you must call pump_events to force an event queue update.</p>
276
277
278
279
280
281</div>
282<h2 id="peep_events_event_num_events_action_">peep_events (event, num_events, action, mask) </h2>
283<div id="peep_events_event_num_events_action_-2">
284<p>Checks the event queue for messages and optionally returns them. </p>
285<pre> my $num_peep_events = SDL::Events::peep_events($event, 127, SDL_PEEKEVENT, SDL_ALLEVENTS);
286
287</pre>
288<p>If action is SDL_ADDEVENT, up to numevents events will be added to the back of the event queue.</p>
1dbe1697 289<p>If action is SDL_PEEKEVENT, up to numevents events at the front of the event queue, matching mask, will be returned and will not be removed from
290the queue.</p>
291<p>If action is SDL_GETEVENT, up to numevents events at the front of the event queue, matching mask, will be returned and will be removed from the
292queue.</p>
162a0989 293<p>The mask parameter is a bitwise OR of SDL::Events::SDL_EVENTMASK(event_type), for all event types you are interested in</p>
294<p>This function is thread-safe.</p>
295<p>You may have to call pump_events before calling this function. Otherwise, the events may not be ready to be filtered when you call peep_events.</p>
296<p>Examples of mask:</p>
297<dl>
298 <dt>SDL_EVENTMASK (SDL_KEYUP)</dt>
299 <dt>(SDL_EVENTMASK (SDL_MOUSEBUTTONDOWN) | SDL_EVENTMASK (SDL_MOUSEBUTTONUP))</dt>
300 <dt>SDL_ALLEVENTS</dt>
301 <dt>SDL_KEYUPMASK</dt>
302 <dt>SDL_ALLEVENTS ^ SDL_QUITMASK</dt>
303</dl>
304
305</div>
306<h3 id="RETURN">RETURN</h3>
307<div id="RETURN_CONTENT">
308<p>Number of Events actually stored or -1 if there was an error</p>
309
310</div>
311<h2 id="poll_event_event">poll_event($event)</h2>
312<div id="poll_event_event_CONTENT">
313<p>Polls for currently pending events. </p>
55bbf7a2 314<p>If $event is not NULL, the next event is removed from the queue and stored in the <a href="SDL-Event.html">SDL::Event</a> structure pointed to by $event.</p>
1dbe1697 315<p>As this function implicitly calls pump_events, you can only call this function in the thread that set the video mode with
316<a href="/SDL-Video.html#set_video_mode">SDL::Video::set_video_mode</a>. </p>
162a0989 317
318</div>
319<h3 id="RETURN-2">RETURN</h3>
320<div id="RETURN_CONTENT-2">
321<p>Returns 1 if there are any pending events, or 0 if there are none available. </p>
322
323</div>
324<h2 id="push_event_event">push_event($event)</h2>
325<div id="push_event_event_CONTENT">
326<p>Pushes an event onto the event queue </p>
1dbe1697 327<p>The event queue can actually be used as a two way communication channel. Not only can events be read from the queue, but the user can also push
328their own events onto it. event is a pointer to the event structure you wish to push onto the queue.
162a0989 329The event is copied into the queue, and the caller may dispose of the memory pointed to after push_event returns.</p>
330<p>Note: Pushing device input events onto the queue doesn't modify the state of the device within SDL. </p>
331<p>This function is thread safe, and can be called from other threads safely.</p>
332
333</div>
334<h3 id="RETURN-3">RETURN</h3>
335<div id="RETURN_CONTENT-3">
336<p>Returns 0 on success or -1 if the event couldn't be pushed.</p>
337
338</div>
339<h2 id="wait_event_event">wait_event($event)</h2>
340<div id="wait_event_event_CONTENT">
341<p>Waits indefinitely for the next available $event, returning 0 if there was an error while waiting for events, 1 otherwise.</p>
342<p>If $event is not NULL, the next event is removed from the queue and stored in $event.</p>
1dbe1697 343<p>As this function implicitly calls SDL_PumpEvents, you can only call this function in the thread that
344<a href="/SDL-Video.html#set_video_mode">SDL::Video::set_video_mode</a>. </p>
162a0989 345
346</div>
347<h3 id="RETURN-4">RETURN</h3>
348<div id="RETURN_CONTENT-4">
349<p>0 if there was an error while waiting for events, 1 otherwise</p>
350
351</div>
cf23a5da 352<h2 id="set_event_filter">set_event_filter</h2>
353<div id="set_event_filter_CONTENT">
55bbf7a2 354<p>Sets up a filter to process all events </p>
355<pre> my $filter = sub { if($_[0]-&gt;type == SDL_ACTIVEEVENT){ return 0} else{ return 1; }};
356
357 SDL::Events::set_event_filter($filter);
358
359</pre>
360
361</div>
362<h3 id="PARAMETER">PARAMETER</h3>
363<div id="PARAMETER_CONTENT">
364<p>set_event_filter takes a coderef that it checks all events again. The callback gets a event in the stack</p>
365<pre> sub { my $event_to_test = shift; ...}
366
367</pre>
368<p>to filter the event return a 0, to pass the filter return a 1. </p>
1dbe1697 369<p>One <strong>Caveat</strong> is if you are filtering SDL_QUIT the event will be filtered if it is non-intterupt call ( Window closes normally ). If it is a
370interrupt SDL_QUIT it will be process on the next event poll. </p>
371<p>Events pushed onto to the queue with <a href="/SDL-Events.html#push_events">SDL::Events::push_events</a> or <a href="/SDL-Events.html#peep_events">SDL::Events::peep_events</a>
372do not get filtered.</p>
55bbf7a2 373<p>This callback may run in a different thread. </p>
cf23a5da 374
375</div>
376<h2 id="get_key_state">get_key_state</h2>
377<div id="get_key_state_CONTENT">
55bbf7a2 378<p>Get a snapshot of the current keyboard state</p>
379<pre> my $keys_ref = SDL::Events::get_key_state();
380
381 print $keys_ref-&gt;[SDLK_RETURN]; # 1 if pressed , 0 if not pressed
382
383</pre>
1dbe1697 384<p>Use <a href="/SDL-Events.html#pump_events">SDL::Events::pump_events</a> to update the state array.</p>
385<p>This function gives you the current state after all events have been processed, so if a key or button has been pressed and released before you
386process events, then the pressed state will never show up in the get_key_state call.</p>
55bbf7a2 387<p>This function doesn't take into account whether shift has been pressed or not.</p>
cf23a5da 388
389</div>
390<h2 id="get_mod_state">get_mod_state</h2>
391<div id="get_mod_state_CONTENT">
55bbf7a2 392<p>Get the state of the modifier keys</p>
393<p>Returns the current state of modifier keys</p>
394<p>Return value is an OR'd combination of KMOD_*</p>
395<pre> SDL::Events::pump_events; #get latest mod_state in buffers
396
397 my $mod_state = SDL::Events::get_mod_state();
398
399 # Check which ones are pressed with
400
401 # no mod pressed?
402
403 print 'no_mod' if ( $mod_state &amp; KMOD_NONE );
404
405 # CTRL or ALT
406
407 print 'ctrl alt' if ($mod_state &amp; KMOD_CTRL || $mod_state &amp; KMOD_ALT );
408
409</pre>
410
411</div>
412<h3 id="MOD_VALUES">MOD VALUES</h3>
413<div id="MOD_VALUES_CONTENT">
414<dl>
415 <dt>KMOD_NONE</dt>
416 <dt>KMOD_LSHIFT</dt>
417 <dt>KMOD_RSHIFT</dt>
418 <dt>KMOD_LCTRL</dt>
419 <dt>KMOD_RCTRL</dt>
420 <dt>KMOD_LALT</dt>
421 <dt>KMOD_RALT</dt>
422 <dt>KMOD_LMETA</dt>
423 <dt>KMOD_RMETA</dt>
424 <dt>KMOD_NUM</dt>
425 <dt>KMOD_CAPS</dt>
426 <dt>KMOD_MODE</dt>
427 <dt>KMOD_CTRL </dt>
428 <dd>
429 <p>same as KMOD_LCTRL|KMOD_RCTRL</p>
430 </dd>
431 <dt>KMOD_SHIFT</dt>
432 <dd>
433 <p>same as KMOD_LSHIFT|KMOD_RSHIFT</p>
434 </dd>
435 <dt>KMOD_ALT</dt>
436 <dd>
437 <p>same as KMOD_LALT|KMOD_RALT</p>
438 </dd>
439 <dt>KMOD_META</dt>
440 <dd>
441 <p>same as KMOD_LMETA|KMOD_RMETA</p>
442 </dd>
443</dl>
cf23a5da 444
445</div>
446<h2 id="set_mod_state">set_mod_state</h2>
447<div id="set_mod_state_CONTENT">
55bbf7a2 448<p>Get the state of the modifier keys</p>
1dbe1697 449<p>The inverse of <a href="/SDL-Events.html#get_mod_state">SDL::Events::get_mod_state</a> allows you to impose modifier key states on your application.</p>
55bbf7a2 450<p>Simply pass your desired modifier states into $modstate. This value can be a OR'd combination of any KMOD* constant.</p>
451<pre> my $modstate = KMOD_LMETA | KMOD_LSHIFT;
452
453</pre>
1dbe1697 454<p>Any KMOD_* constant see <a href="/SDL-Events.html#get_mod_state">SDL::Events::get_mod_state</a> for constants.
55bbf7a2 455 SDL::Events::set_mod_state( $modstate );</p>
cf23a5da 456
457</div>
458<h2 id="event_state">event_state </h2>
459<div id="event_state_CONTENT">
55bbf7a2 460<p>Allows you to set the state of processing certain events</p>
461<pre> SDL::Events::event_state( $type, $state );
462
463</pre>
464<p>A list of $type(s) can be found in <a href="SDL-Event.html">SDL::Event</a></p>
465
466</div>
467<h3 id="STATES">STATES</h3>
468<div id="STATES_CONTENT">
469<dl>
470 <dt>SDL_IGNORE</dt>
471 <dd>
472 <p>The event of $type will be automatically dropper from the event queue and will not be filtered.</p>
473 </dd>
474 <dt>SDL_ENABLE</dt>
475 <dd>
476 <p>The event of $type will be processed normally. This is default.</p>
477 </dd>
478 <dt>SDL_QUERY</dt>
479 <dd>
480 <p>The current processing state of the $type will be returned</p>
481 </dd>
482</dl>
cf23a5da 483
484</div>
485<h2 id="get_key_name">get_key_name</h2>
486<div id="get_key_name_CONTENT">
55bbf7a2 487<p>Gets the name of the a SDL virtual keysym</p>
488<pre> my $event = SDL::Event-&gt;new();
489
490 while( SDL::Events::poll_event($event) )
491 {
492 my $key = $event-&gt;key_sym;
493 $key_str = SDL::Events::get_key_name($key);
494 }
495
496</pre>
497<p>Returns a string with the name of the key sym.</p>
cf23a5da 498
499</div>
500<h2 id="enable_unicode">enable_unicode </h2>
501<div id="enable_unicode_CONTENT">
55bbf7a2 502<p>Enable/Disable UNICODE translation</p>
503<pre> my $previous_translation_mode = SDL::Events::enable_unicode( 1 ); #enable
504 $previous_translation_mode = SDL::Events::enable_unicode( 0 ); #disables
505
506</pre>
1dbe1697 507<p>To obtain the character codes corresponding to received keyboard events, Unicode translation must first be turned on using this function. The
508translation incurs a slight overhead for each keyboard event and is therefore disabled by default. For each subsequently recieved key down event,
509the unicode member of the <a href="/SDL-Event.html#key_sym">SDL::Event::key_sym</a> provided structure will be then contain the corresponding character code, or
510otherwise zero.</p>
55bbf7a2 511<p>A value of 1 for enabling, 0 for disabling and -1 for unchanged. -1 is usefull for querying the current translation mode.</p>
512<p>Only key press events will be translated not release events.</p>
513<p>Returns the previous translation mode as (1,0).</p>
cf23a5da 514
515</div>
516<h2 id="enable_key_repeat">enable_key_repeat </h2>
517<div id="enable_key_repeat_CONTENT">
55bbf7a2 518<p>Sets keyboard repeat rate</p>
519<pre> my $success = SDL::Events::enable_key_repeat( $delay, $interval );
520
521</pre>
1dbe1697 522<p>Enables or disables the keyboard repeat rate. $delay specifies how long the key must be pressed before it begins repeating, it then repleats at the
523speed specified by $interval. Both $delay and $interval are expressed in milliseconds.</p>
55bbf7a2 524<p>Setting $delay to 0 disables key repeating completely. Good default values are SDL_DEFAULT_REPEAT_DELAY and SDL_DEFAULT_REPEAT_INTERVAL.</p>
525<p>Return 0 on success and -1 on fail.</p>
cf23a5da 526
527</div>
528<h2 id="get_mouse_state">get_mouse_state </h2>
529<div id="get_mouse_state_CONTENT">
55bbf7a2 530<p>Retrives the current state of the mouse</p>
1dbe1697 531<pre> my ($mask,$x,$y) = @{ SDL::Events::get_mouse_state( ) };
55bbf7a2 532
1dbe1697 533 print 'Button Left pressed' if ($mask &amp; SDL_BUTTON_LMASK);
55bbf7a2 534
1dbe1697 535 print 'Button Right pressed' if ($mask &amp; SDL_BUTTON_RMASK);
55bbf7a2 536
1dbe1697 537 print 'Button Middle pressed' if ($mask &amp; SDL_BUTTON_MMASK);
55bbf7a2 538
1dbe1697 539 print $x.','.$y;
55bbf7a2 540
541</pre>
542<p>The current button state is returned as a button $bitmask, which can be tested using the the above constants </p>
cf23a5da 543
544</div>
545<h2 id="get_relative_mouse_state">get_relative_mouse_state </h2>
546<div id="get_relative_mouse_state_CONTENT">
55bbf7a2 547<p>Retrives the current relative state of the mouse</p>
1dbe1697 548<pre> my ($mask,$x,$y) = @{ SDL::Events::get_mouse_state( ) };
55bbf7a2 549
1dbe1697 550 print 'Button Left pressed' if ($mask &amp; SDL_BUTTON_LMASK);
55bbf7a2 551
1dbe1697 552 print 'Button Right pressed' if ($mask &amp; SDL_BUTTON_RMASK);
55bbf7a2 553
1dbe1697 554 print 'Button Middle pressed' if ($mask &amp; SDL_BUTTON_MMASK);
55bbf7a2 555
1dbe1697 556 print $x.','.$y; # this is relative to the last postion of the mouse
55bbf7a2 557
558</pre>
559<p>The current button state is returned as a button $bitmask, which can be tested using the the above constants </p>
560
561
562
563
cf23a5da 564
565</div>
566<h2 id="get_app_state">get_app_state </h2>
567<div id="get_app_state_CONTENT">
55bbf7a2 568<p>Gets the state of the application</p>
569<pre> my $app_state = SDL::Events::get_app_state();
570
571</pre>
572<p>The $app_state is a bitwise combination of:</p>
573<dl>
574 <dt>SDL_APPMOUSEFOCUS</dt>
575 <dd>
576 <p>Application has mouse focus</p>
577<pre> warn 'mouse focus' if $app_state &amp; SDL_APPMOUSEFOCUS
578
579</pre>
580 </dd>
581 <dt>SDL_APPINPUTFOCUS</dt>
582 <dd>
583 <p>Application has keyboard focus</p>
584<pre> warn 'keyboard focus' if $app_state &amp; SDL_APPINPUTFOCUS
585
586
587
588
589</pre>
590 </dd>
591 <dt>SDL_APPACTIVE</dt>
592 <dd>
593 <p>Application is visible</p>
594<pre> warn 'Application Visible' if $app_state &amp; SDL_APPACTIVE
cf23a5da 595
55bbf7a2 596</pre>
b0e2356c 597 </dd>
598</dl>
55bbf7a2 599
600</div>
601<h2 id="joystick_event_state">joystick_event_state </h2>
602<div id="joystick_event_state_CONTENT">
b0e2356c 603<p>Enable/disable joystick event polling</p>
55bbf7a2 604<pre> my $status = SDL::Events::joystick_event_state( $state );
cf23a5da 605
55bbf7a2 606</pre>
1dbe1697 607<p>This function is used to enable or disable joystick event processing. With joystick event processing disabled you will have to update joystick
608states with <a href="/SDL-Joystick.html#update">SDL::Joystick::update</a> and read the joystick information manually. $state can be:</p>
b0e2356c 609<dl>
55bbf7a2 610 <dt>SDL_QUERY</dt>
611 <dt>SDL_ENABLE </dt>
612 <dt>SDL_IGNORE</dt>
613 <dd>
614 <p>Joystick event handling is default. Even if joystick event processing is enabled, individual joysticks must be opened before they generate events</p>
615 </dd>
616</dl>
617<p><strong>Warning:</strong> Calling this function may delete all events currently in SDL's event queue.</p>
618<p>If $state is SDL_QUERY then the current state is returned, otherwise the new processing state is returned.</p>
cf23a5da 619
620</div>
162a0989 621<h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
622<div id="SEE_ALSO_CONTENT">
c7e8d3c6 623<p><a href="SDL-Event.html">SDL::Event</a>, <a href="SDL-Video.html">SDL::Video</a></p>
624
625</div>
626<h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
627<div id="AUTHORS_CONTENT">
1dbe1697 628<p>See <a href="/SDL.html#AUTHORS">/SDL.html#AUTHORS</a>.</p>
162a0989 629
630</div>
631</div>