I think that the best design will check events in one place - even if in the factored function or method outside the mainloop code and store all the event data notnt in other objects (as attributes) or variables.
For example, you can save a link to a Python set with all the current keys pressed, the current mouse position and button state, and pass these variables to functions and methods.
Otherwise, if you need to check only the pressed keys and the state of the mouse (and the position of the pointer), you can completely bypass events (only by saving the calls to pygame.event.pump () on mainloop). The pygame.key.get_pressed function is my favorite way to read the keyboard - it returns a sequence with as many positions as there are key codes, and each key pressed has a corresponding position set to True in this vector. (Key codes are available as constants in pygame.locals, such as K_ESC, K_a, K_LEFT, etc.).
Example:
if pygame.key.get_pressed()[pygame.K_ESCAPE]: pygame.quit()
The mouse module (documented at http://www.pygame.org/docs/ref/mouse.html ) allows you to get the state of the mouse without using events.
And finally, if you really want to receive events, I see that this is an opportunity to transfer events to the queue, if they will not be used, with a call to pygame.event.post - this call can be placed, for example, in else in the if / elif sequence where you check some state in the event queue.
source share