5 SDL::Event - a SDL perl extension
10 my $event = new SDL::Event; # create a new event
11 $event->pump(); # pump all events from SDL Event Queue
12 $event->poll(); # Get the top one from the queue
13 while ($event->wait()) {
14 my $type = $event->type(); # get event type
16 exit if $type == SDL_QUIT;
21 C<SDL::Event> offers an object-oriented approach to SDL events. By creating
22 an instance of SDL::Event via new() you can wait for events, and then determine
23 the type of the event and take an appropriate action.
27 Here is an example of a simple event handler loop routine.
28 See also L<SDL::App::loop>.
31 my ($self,$href) = @_;
32 my $event = new SDL::Event;
33 while ( $event->wait() ) {
34 # ... insert here your event handling like:
35 if ( ref($$href{$event->type()}) eq "CODE" ) {
36 &{$$href{$event->type()}}($event);
46 Create a new event object.It returns a SDL::Event.
50 Returns the type of the event, see list of exported symbols for which are
55 SDL::Events::pump gathers all the pending input information from devices and places
56 it on the event queue.
57 Without calls to pump no events would ever be placed on the queue.
58 Often the need for calls to pump is hidden from the user
59 since C</SDL::Events::poll> and C<SDL::Events::wait_event implicitly call pump.
60 However, if you are not polling or waiting for events (e.g. you are filtering them),
61 then you must call pump force an event queue update.
62 pump doesn't return any value and doesn't take any parameters.
64 Note: You can only call this function in the thread that set the video mode.
69 Polls for currently pending events.
70 If event is not undef, the next event is removed from the queue and returned as a C< SDL::Event>.
71 As this function implicitly calls C<SDL::Events::pump>, you can only call this function in the thread that set the video mode.
72 it take a SDL::Event as first parameter.
76 Waits indefinitely for the next available event, returning undef if there was an error while waiting for events,
77 a L< SDL::Event> otherwise.
78 If event is not NULL, the next event is removed.
79 As this function implicitly calls L<SDL::Events::pump>, you can only call this function in the thread that set the video mode.
80 WaitEvent take a SDL::Event as first parameter.
82 =head2 set( type, state )
84 Set the state for all events of the given event's type
86 =head2 set_unicode( toggle )
88 Toggle unicode on the event.
90 =head2 set_key_repeat( delay, interval)
92 Sets the delay and intervall of the key repeat rate (e.g. when a user
93 holds down a key on the keyboard).
95 =head2 active_gain(event)
97 active_gain return the active gain from the SDL::Event given as first parameter.
99 =head2 active_state(event)
101 active_state return the active state from the SDL::Event given as first parameter.
103 =head2 key_state(event)
105 key_state return the active key state from the SDL::Event given as first parameter.
110 key_sym return the key pressed/released information from the SDL::Event given as first parameter.
112 =head2 get_key_name(key)
114 get_key_name get the name of an SDL virtual keysym.
115 it returns the key name.
117 =head2 key_mod(event)
119 key_mod return the mod keys pressed information from the SDL::Event given as first parameter.
121 =head2 key_unicode(event)
123 key_unicode return the unicode translated keys pressed/released information from the SDL::Event given as first parameter.
125 =head2 key_scancode(event) * to move in SDL::Game::Keyboard
127 key_scancode return the hardware specific keyboard scan code from the SDL::Event given as first parameter.
129 =head2 motion_state(event) * to move in SDL::Game::Mouse
131 motion_state return the state of the mouse button from the SDL::Event given as first parameter.
133 =head2 motion_x(event) * to move in SDL::Game::Mouse
135 Returns the motion of the mouse in X direction as an absolute value.
136 It take a SDL::Event as first parameter.
138 =head2 motion_y(event) * to move in SDL::Game::Mouse
140 Returns the motion of the mouse in Y direction as an absolute value.
141 It take a SDL::Event as first parameter.
143 =head2 motion_xrel(event) * to move in SDL::Game::Mouse
145 Returns the motion of the mouse in X direction as a relative value.
146 It take a SDL::Event as first parameter.
148 =head2 motion_yrel(event) * to move in SDL::Game::Mouse
150 Returns the motion of the mouse in Y direction as a relative value.
151 It take a SDL::Event as first parameter.
153 =head2 button_state(event) * to move in SDL::Game::Mouse
155 Returns the state of the mouse buttons.
156 It take a SDL::Event as first parameter.
158 =head2 button_x(event) * to move in SDL::Game::Mouse
160 Return the X position of the mouse at keypress.it take a SDL::Event as first parameter.
162 =head2 button_y(event) * to move in SDL::Game::Mouse
164 Return the Y position of the mouse at keypress.it take a SDL::Event as first parameter.
166 =head2 button(event) * to move in SDL::Game::Mouse
168 Return the mouse button index (SDL_BUTTON_LEFT, SDL_BUTTON_MIDDLE, SDL_BUTTON_RIGHT, SDL_BUTTON_WHEELUP, SDL_BUTTON_WHEELDOWN)
173 Documentation by Tels <http://bloodgate.com/>