SDL::Event - a SDL perl extension


 $event = new SDL::Event;


        SDL::Event->new(); creates a SDL_Event structure, into
which events may be stored.


        This function returns the event type which will be one of

Gathering Events


These three methods can be used to gather new events. Poll and pump should be used together. Pump will collect events, and poll will read events from the stack, returning 0 if no events were found. Similarly wait will wait for an event to occur, and then return.

Active Events

These events indicate a change in the state of the application. The methods which access the event's properties are:


The possible states that an event may return are: SDL_APPMOUSEFOCUS, SDL_APPINPUTFOCUS, and SDL_APPACTIVE.

Key Events

Everytime a key is pressed or release, while the app has input focus, a key event will be generated. The following methods provide access to the event's fileds:


Key_state will return either SDL_PRESSED or SDL_RELEASED. Key_name will return a string giving the name of the key. Sym will return the SDL key symbol code, which can be checked against the SDLK_* entries as specified in the SDL documentation. (ie sym 27 is SDLK_ESCAPE). Likewise, key_mod will return the current modifier state of the key and can be or'ed against the KMOD_* masks as per the SDL documentation.

To enable unicode support, one must first call


there after each event will fill out the unicode field. The key_unicode function returns the integer of the unicode key. Similarly, key_scancode will return the raw scancode from the key event.

Mouse Events

There are two types of mouse related events, motion and button. The exact type is important as there are separate methodss for reading from each. For motion events one should use:


For button events the following are applicable:


Button_state will either be SDL_PRESSED or SDL_RELEASED, while button will contain the number of the button pressed, 1, 2, 3, etc.

Other things

Additionally, you can use the method 'set' to make the SDL ignore or re-enable event types. For example, you can ignore all SDL_SYSWMEVENT events with the command:


This is highly recommended as you will have to process fewer events this way. You can also enable key repeats using the method:


It should be noted that there is currently no support for the SYSWMEVENT events in this structure, as these are really best dealt with C level code. This may change in the future.


David J. Goehrig


perl(1) SDL::App(3).