pygame   documentation
||  Home  ||  Help Contents  ||
 
|| pygame || cdrom || constants || cursor || display || draw ||
|| event || font || image || joystick || key || mixer ||
|| mixer_music || mouse || movie || sndarray || surfarray || time ||
|| transform ||
 
|| CD || Channel || Clock || Font || Joystick || Movie ||
|| Overlay || Rect || Sound || Surface ||
 
|| color || cursors || sprite ||

pygame.event

Pygame handles all it's event messaging through an event queue. The routines in this module help you manage that event queue. The input queue is heavily dependent on the pygame display module. If the display has not been initialized and a video mode not set, the event queue will not really work.
 
The queue is a regular queue of Event objects, there are a variety of ways to access the events it contains. From simply checking for the existance of events, to grabbing them directly off the stack.
 
All events have a type identifier. This event type is in between the values of NOEVENT and NUMEVENTS. All user defined events can have the value of USEREVENT or higher. It is recommended make sure your event id's follow this system.
 
To get the state of various input devices, you can forego the event queue and access the input devices directly with their appropriate modules; mouse, key, and joystick. If you use this method, remember that pygame requires some form of communication with the system window manager and other parts of the platform. To keep pygame in synch with the system, you will need to call pygame.event.pump() to keep everything current. You'll want to call this function usually once per game loop.
 
The event queue offers some simple filtering. This can help performance slightly by blocking certain event types from the queue, use the pygame.event.set_allowed() and pygame.event.set_blocked() to work with this filtering. All events default to allowed.
 
Also know that you will not receive any events from a joystick device, until you have initialized that individual joystick from the joystick module.

 

An Event object contains an event type and a readonly set of member data. The Event object contains no method functions, just member data. Event objects are retrieved from the pygame event queue. You can create your own new events with the pygame.event.Event() function.
 
All Event objects contain an event type identifier in the Event.type member. You may also get full access to the Event's member data through the Event.dict method. All other member lookups will be passed through to the Event's dictionary values.
 
While debugging and experimenting, you can print the Event objects for a quick display of its type and members. Events that come from the system will have a guaranteed set of member items based on the type. Here is a list of the Event members that are defined with each type.
QUITnone
ACTIVEEVENTgain, state
KEYDOWNunicode, key, mod
KEYUPkey, mod
MOUSEMOTIONpos, rel, buttons
MOUSEBUTTONUPpos, button
MOUSEBUTTONDOWNpos, button
JOYAXISMOTIONjoy, axis, value
JOYBALLMOTIONjoy, ball, rel
JOYHATMOTIONjoy, hat, value
JOYBUTTONUPjoy, button
JOYBUTTONDOWNjoy, button
VIDEORESIZEsize
VIDEOEXPOSEnone
USEREVENTcode

Event - create new event object
clear - remove all of an event type from the queue
event_name - name for event type
get - get all of an event type from the queue
get_blocked - checks if an event is being blocked
get_grab - query the state of input grabbing
peek - query if any of event types are waiting
poll - get an available event
post - place an event on the queue
pump - update the internal messages
set_allowed - allows certain events onto the queue
set_blocked - blocks certain events from the queue
set_grab - grab all input events
wait - wait for an event

Event
pygame.event.Event(type, [dict], [keyword_args]) -> Event
 
clear
pygame.event.clear([type]) -> None
 
event_name
pygame.event.event_name(event type) -> string
 
get
pygame.event.get([type]) -> list of Events
 
get_blocked
pygame.event.get_blocked(type) -> boolean
 
get_grab
pygame.event.get_grab() -> bool
 
peek
pygame.event.peek([type]) -> bool
 
poll
pygame.event.poll() -> Event
 
post
pygame.event.post(Event) -> None
 
pump
pygame.event.pump() -> None
 
set_allowed
pygame.event.set_allowed(type) -> None
 
set_blocked
pygame.event.set_blocked(type) -> None
 
set_grab
pygame.event.set_grab(bool) -> None
 
wait
pygame.event.wait() -> Event