Contains event routines and object.


  • pygame.event.event(type, dict) -> Event
  • - create new event object
  • pygame.event.event_name(event type) -> string
  • - name for event type
  • pygame.event.set_grab(bool) -> None
  • - grab all input events
  • pygame.get_grab() -> bool
  • - query the state of input grabbing
  • pygame.event.pump() -> None
  • - update the internal messages
  • pygame.event.wait() -> Event
  • - wait for an event
  • pygame.event.poll() -> Event
  • - get an available event
  • pygame.event.get([type]) -> list of Events
  • - get all of an event type from the queue
  • pygame.event.peek([type]) -> bool
  • - query if any of event types are waiting
  • pygame.event.post(Event) -> None
  • - place an event on the queue
  • pygame.event.set_allowed(type) -> None
  • - allows certain events onto the queue
  • pygame.event.set_blocked(type) -> None
  • - blocks certain events from the queue


    pygame.event.event(type, dict) -> Event

    Creates a new event object. The type should be one of SDL's event numbers, or above USER_EVENT. The given dictionary contains a list of readonly attributes that will be members of the event object.


    pygame.event.event_name(event type) -> string

    Returns the standard SDL name for an event type. Mainly helpful for debugging, when trying to determine what the type of an event is.


    pygame.event.set_grab(bool) -> None

    Grabs all mouse and keyboard input for the display. Grabbing the input is not neccessary to receive keyboard and mouse events, but it ensures all input will go to your application. It also keeps the mouse locked inside your window. Set the grabbing on or off with the boolean argument. It is best to not always grab the input, since it prevents the end user from doing anything else on their system.


    pygame.get_grab() -> bool

    Returns true if the input is currently grabbed to your application.


    pygame.event.pump() -> None

    Pumping the message queue is important if you are not getting events off the message queue. The pump will allow pyGame to communicate with the window manager, which helps keep your application responsive, as well as updating the state for various input devices.


    pygame.event.wait() -> Event

    Returns the current event on the queue. If there are no messages waiting on the queue, this will not return until one is available. Sometimes it is important to use this wait to get events from the queue, it will allow your application to idle when the user isn't doing anything with it.


    pygame.event.poll() -> Event

    Returns next event on queue. If there is no event waiting on the queue, this will return a NOEVENT event. This event type evaluates to 0, so it is easy to check for.


    pygame.event.get([type]) -> list of Events

    Pass this a type of event that you are interested in, and it will return a list of all matching event types from the queue. If no types are passed, this will return all the events from the queue. You may also optionally pass a sequence of event types. For example, to fetch all the keyboard events from the queue, you would call, 'pygame.event.get([KEYDOWN,KEYUP])'.


    pygame.event.peek([type]) -> bool

    Pass this a type of event that you are interested in, and it will return true if there are any of that type of event on the queue. If no types are passed, this will return true if any events are on the queue. You may also optionally pass a sequence of event types. For example, to find if any keyboard events are on the queue, you would call, 'pygame.event.peek([KEYDOWN,KEYUP])'.


    pygame.event.post(Event) -> None

    This will place an event onto the queue. This is most useful for putting your own USEREVENT's onto the queue.


    pygame.event.set_allowed(type) -> None

    By default, all events will appear from the queue. After you have blocked some event types, you can use this to re-enable them. You can optionally pass a sequence of event types.


    pygame.event.set_blocked(type) -> None

    By default, all events will appear from the queue. This will allow you to prevent event types from appearing on the queue. You can optionally pass a sequence of event types.