0

I tried running this code but I do not get any output.

while running:
    for event in pygame.event.get():
        print("event")  # Checking if it detects an event
        if event.type == pygame.MOUSEBUTTONDOWN:
            print("Mouse")  # Checking if it detects the click
        elif event.type == pygame.KEYDOWN:
            print("Key")  # Checking if it detects any key being pressed
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Juhi
  • 23
  • 3
  • Are you sure running is true? – Leau Dec 24 '21 at 14:49
  • I call it one other time: `for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit()` exit() – Juhi Dec 24 '21 at 15:13
  • 2
    This is the problem. Get the list of events once (`event_list = pygame.event.get()`) and use the list in the the event loops (`for event in event_list:`). See [Faster version of 'pygame.event.get()'. Why are events being missed and why are the events delayed?](https://stackoverflow.com/questions/58086113/faster-version-of-pygame-event-get-why-are-events-being-missed-and-why-are/58087070#58087070) – Rabbid76 Dec 24 '21 at 15:13
  • I tried running this code and it only prints 'event', not 'Mouse' or key `event_list = pygame.event.get() while running: for event in event_list: print("event") if event.type == pygame.MOUSEBUTTONDOWN: print("Mouse") elif event.type == pygame.KEYDOWN: print("Key") ` – Juhi Dec 24 '21 at 15:22
  • Read [Faster version of 'pygame.event.get()'. Why are events being missed and why are the events delayed?](https://stackoverflow.com/questions/58086113/faster-version-of-pygame-event-get-why-are-events-being-missed-and-why-are/58087070#58087070) ! You have to get the list of events **in** the application loop. `while running: ` `event_list = pygame.event.get()` ... – Rabbid76 Dec 24 '21 at 15:23

0 Answers0