Python Forum
Problem with pygame.event.clear
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with pygame.event.clear
#2
Hello, instead of immediately processing key events as they occur, I think you can queue them and process them one at a time. This ensures that only one key event is processed before moving on to the next trial. You can use a list or a queue to store the key events and process them sequentially.
online games
Here's an example of how you can modify your code to implement event queuing:
python
event_queue = []  # Create an empty event queue

# Inside the event loop
for event in pygame.event.get():
    if event.type == pygame.KEYDOWN:
        event_queue.append(event)  # Add key events to the queue

# Process the key events one by one
for event in event_queue:
    if event.key == pygame.K_LEFT:
        # Process left key event
    elif event.key == pygame.K_RIGHT:
        # Process right key event
    elif event.key == pygame.K_ESCAPE:
        # Process escape key event

event_queue.clear()  # Clear the event queue after processing
```
This way, only the events in the queue will be processed, and any other key events that occurred during the trial will be ignored.
Reply


Messages In This Thread
Problem with pygame.event.clear - by qq12346 - Jan-25-2022, 05:46 AM
RE: Problem with pygame.event.clear - by patriciainman - Oct-05-2023, 08:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pygame double jump problem Yegor123 3 2,680 May-02-2023, 09:34 PM
Last Post: sudoku6
  (HELP GREATLY APPRECIATED) New user- Huge Pygame Installation Problem! Jbomb 1 2,890 Jan-12-2021, 07:32 PM
Last Post: MK_CodingSpace
  problem with pygame Aladdin 3 4,285 Jun-25-2020, 01:41 PM
Last Post: Aladdin
  Problem with music - Pygame.error GaseBall 1 3,256 Nov-28-2019, 07:46 PM
Last Post: SheeppOSU
  [PyGame] Rotation Problem in PyGame thunderbird028 1 2,751 Nov-14-2019, 06:49 AM
Last Post: Windspar
  [PyGame] Pong game key.event problem erickDarko 2 4,261 Dec-12-2018, 03:17 PM
Last Post: erickDarko
  My Pygame Project's Problem **huh** osmanb06 2 3,729 Nov-06-2018, 09:27 AM
Last Post: osmanb06
  Coding problem in a Pygame Sghet 4 8,127 Aug-13-2018, 05:39 PM
Last Post: MTGReen
  [PyGame] Problem importing pygame / installing pygame Klar 4 9,355 Dec-16-2017, 05:48 PM
Last Post: Klar
  Importing pygame Mac problem Benjipincus 1 3,116 Dec-16-2017, 01:54 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020