X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pages%2FSDL-Events.html-inc;h=32a08a6098d8d094b3283b9989e7a3dc3d9ab883;hb=55bbf7a209993f4172fd7e6555dda0947b844089;hp=864e4baafcec747f01780978c7bf105214b7877e;hpb=cf23a5dab86667dca8475ee830e684c9944f115f;p=sdlgit%2FSDL-Site.git diff --git a/pages/SDL-Events.html-inc b/pages/SDL-Events.html-inc index 864e4ba..32a08a6 100644 --- a/pages/SDL-Events.html-inc +++ b/pages/SDL-Events.html-inc @@ -26,11 +26,20 @@
-Most likely you just want to know how to get events for you app. - use SDL; +
Most likely you just want to know how to get events for you app.
+use SDL; use SDL::Event; - use SDL::Events; -SDL::init(SDL_INIT_VIDEO); # Event can only be grabbed in the same thread as this + use SDL::Events; + + SDL::init(SDL_INIT_VIDEO); # Event can only be grabbed in the same thread as this ... @@ -138,8 +148,8 @@ However, if you are not polling or waiting for events (e.g. you are filtering thpoll_event($event)
Polls for currently pending events.
-If $event is not NULL, the next event is removed from the queue and stored in the SDL::Event structure pointed to by $event.
-As this function implicitly calls pump_events, you can only call this function in the thread that set the video mode with SDL::Video::set_video_mode.
+If $event is not NULL, the next event is removed from the queue and stored in the SDL::Event structure pointed to by $event.
+As this function implicitly calls pump_events, you can only call this function in the thread that set the video mode with SDL::Video::set_video_mode.
RETURN
@@ -165,7 +175,7 @@ The event is copied into the queue, and the caller may dispose of the memory poiWaits indefinitely for the next available $event, returning 0 if there was an error while waiting for events, 1 otherwise.
If $event is not NULL, the next event is removed from the queue and stored in $event.
-As this function implicitly calls SDL_PumpEvents, you can only call this function in the thread that SDL::Video::set_video_mode.
+As this function implicitly calls SDL_PumpEvents, you can only call this function in the thread that SDL::Video::set_video_mode.
RETURN
@@ -175,59 +185,269 @@ The event is copied into the queue, and the caller may dispose of the memory poi
Sets up a filter to process all events
+my $filter = sub { if($_[0]->type == SDL_ACTIVEEVENT){ return 0} else{ return 1; }}; + + SDL::Events::set_event_filter($filter); + ++ +
set_event_filter takes a coderef that it checks all events again. The callback gets a event in the stack
+sub { my $event_to_test = shift; ...} + ++
to filter the event return a 0, to pass the filter return a 1.
+One Caveat is if you are filterign SDL_QUITEVENT the event will be filtered if it is non-intterupt call ( Window closes normally ). If it is a interrupt SDL_QUITEVENT it will be process on the next event poll.
+Events pushed onto to the queue with SDL::Events::push_events or SDL::Events::peep_events do not get filtered.
+This callback may run in a different thread.
Get a snapshot of the current keyboard state
+my $keys_ref = SDL::Events::get_key_state(); + + print $keys_ref->[SDLK_RETURN]; # 1 if pressed , 0 if not pressed + ++
Use SDL::Events::pump_events to update the state array.
+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 process events, then the pressed state will never show up in the get_key_state call.
+This function doesn't take into account whether shift has been pressed or not.
Get the state of the modifier keys
+Returns the current state of modifier keys
+Return value is an OR'd combination of KMOD_*
+SDL::Events::pump_events; #get latest mod_state in buffers + + my $mod_state = SDL::Events::get_mod_state(); + + # Check which ones are pressed with + + # no mod pressed? + + print 'no_mod' if ( $mod_state & KMOD_NONE ); + + # CTRL or ALT + + print 'ctrl alt' if ($mod_state & KMOD_CTRL || $mod_state & KMOD_ALT ); + ++ +
same as KMOD_LCTRL|KMOD_RCTRL
+same as KMOD_LSHIFT|KMOD_RSHIFT
+same as KMOD_LALT|KMOD_RALT
+same as KMOD_LMETA|KMOD_RMETA
+Get the state of the modifier keys
+The inverse of SDL::Events::get_mod_state allows you to impose modifier key states on your application.
+Simply pass your desired modifier states into $modstate. This value can be a OR'd combination of any KMOD* constant.
+my $modstate = KMOD_LMETA | KMOD_LSHIFT; + ++
Any KMOD_* constant see SDL::Events::get_mod_state for constants. + SDL::Events::set_mod_state( $modstate );
Allows you to set the state of processing certain events
+SDL::Events::event_state( $type, $state ); + ++
A list of $type(s) can be found in SDL::Event
+ +The event of $type will be automatically dropper from the event queue and will not be filtered.
+The event of $type will be processed normally. This is default.
+The current processing state of the $type will be returned
+Gets the name of the a SDL virtual keysym
+my $event = SDL::Event->new(); + + while( SDL::Events::poll_event($event) ) + { + my $key = $event->key_sym; + $key_str = SDL::Events::get_key_name($key); + } + ++
Returns a string with the name of the key sym.
Enable/Disable UNICODE translation
+my $previous_translation_mode = SDL::Events::enable_unicode( 1 ); #enable + $previous_translation_mode = SDL::Events::enable_unicode( 0 ); #disables + ++
To obtain the character codes corresponding to received keyboard events, Unicode translation must first be turned on using this function. The translation incurs a slight overhead for each keyboard event and is therefore disabled by default. For each subsequently recieved key down event, the unicode member of the SDL::Event::key_sym provided structure will be then contain the corresponding character code, or otherwise zero.
+A value of 1 for enabling, 0 for disabling and -1 for unchanged. -1 is usefull for querying the current translation mode.
+Only key press events will be translated not release events.
+Returns the previous translation mode as (1,0).
Sets keyboard repeat rate
+my $success = SDL::Events::enable_key_repeat( $delay, $interval ); + ++
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 speed specified by $interval. Both $delay and $interval are expressed in milliseconds.
+Setting $delay to 0 disables key repeating completely. Good default values are SDL_DEFAULT_REPEAT_DELAY and SDL_DEFAULT_REPEAT_INTERVAL.
+Return 0 on success and -1 on fail.
Retrives the current state of the mouse
+my ($mask,$x,$y) = @{ SDL::Events::get_mouse_state( ) }; + + print 'Button Left pressed' if ($mask & SDL_BUTTON_LMASK); + + print 'Button Right pressed' if ($mask & SDL_BUTTON_RMASK); + + print 'Button Middle pressed' if ($mask & SDL_BUTTON_MMASK); + + print $x.','.$y; + ++
The current button state is returned as a button $bitmask, which can be tested using the the above constants
Retrives the current relative state of the mouse
+my ($mask,$x,$y) = @{ SDL::Events::get_mouse_state( ) }; + + print 'Button Left pressed' if ($mask & SDL_BUTTON_LMASK); + + print 'Button Right pressed' if ($mask & SDL_BUTTON_RMASK); + + print 'Button Middle pressed' if ($mask & SDL_BUTTON_MMASK); + + print $x.','.$y; # this is relative to the last postion of the mouse + ++
The current button state is returned as a button $bitmask, which can be tested using the the above constants
+ + + +Gets the state of the application
+my $app_state = SDL::Events::get_app_state(); + ++
The $app_state is a bitwise combination of:
+Application has mouse focus
+warn 'mouse focus' if $app_state & SDL_APPMOUSEFOCUS + ++
Application has keyboard focus
+warn 'keyboard focus' if $app_state & SDL_APPINPUTFOCUS + + + + ++
Application is visible
+warn 'Application Visible' if $app_state & SDL_APPACTIVE -
Enable/disable joystick event polling
+my $status = SDL::Events::joystick_event_state( $state ); ++
This function is used to enable or disable joystick event processing. With joystick event processing disabled you will have to update joystick states with SDL_JoystickUpdate and read the joystick information manually. $state can be:
+ +Joystick event handling is default. Even if joystick event processing is enabled, individual joysticks must be opened before they generate events
+Warning: Calling this function may delete all events currently in SDL's event queue.
+If $state is SDL_QUERY then the current state is returned, otherwise the new processing state is returned.