Pygame.event.get() Not Returning Events When Inside a Thread
When utilizing the code provided to handle user inputs within a Pac-Man-style game, the issue arises when events are not received upon pressing keyboard keys. However, mouse movements still trigger event responses.
This anomaly is encountered because the event subsystem in Pygame operates exclusively within the main thread. Despite attempts to minimize unregistered keystrokes by incorporating a thread, the documentation explicitly states:
The event subsystem should be called from the main thread.
Therefore, although posting events from other threads is feasible, processing the event queue remains the prerogative of the main thread. To resolve this issue, events must be obtained within the main thread, ensuring their proper functionality within your game loop.
The above is the detailed content of Why Doesn't Pygame.event.get() Return Events When Used in a Thread?. For more information, please follow other related articles on the PHP Chinese website!