I was trying to handle inputs for my pygame project and I wanted to clear all the pygame.MOUSEBUTTONDOWN events from previous cycles while keeping all the unprocessed inputs. I know a good method to do it and minimize input loss is to just clear the events after processing them, but I didn't want to risk losing any input, so I created a way to handle the inputs, but made a mistake that resulted in a code that works the same way as the following: in the following code the show() and click() methods are methods I created for a button class def run(self): got_mouse_click = False while True: for event in pygame.event.get(exclude=[pygame.MOUSEBUTTONDOWN]): if event.type == pygame.QUIT: pygame.quit() sys.exit() pygame.event.clear(eventtype = pygame.MOUSEBUTTONDOWN) self.screen.fill("aqua") self.game_button.show(self.screen) self.options_button.show(self.screen) self.quit_button.show(self.screen) if self.game_button.click(): self.save_menu.run() elif self.options_button.click(): self.options.run() elif self.quit_button.click(): pygame.quit() sys.exit() pygame.display.flip() This is the click() method: def click(self, *, button_to_click=1, delete_events:bool=True): #left click is 1, middle button click is 2, right click is 3, mouse wheel up is 4, mouse wheel down is 5 x, y = pygame.mouse.get_pos() if self.rect.collidepoint(x, y): for event in pygame.event.get(eventtype=pygame.MOUSEBUTTONDOWN): # puts the events back in the event list if delete_events = False if not delete_events: pygame.event.post(event) # checks for mouse click if event.type == pygame.MOUSEBUTTONDOWN: if event.button == button_to_click: self.execute() return True return False The previous code has a low input loss when pygame.event.clear is inside the for loop (like in the code sample), but has a high input loss if I take it out of the for loop, no matter if I put it before or after the loop: This works for event in pygame.event.get(exclude=[pygame.MOUSEBUTTONDOWN]): if event.type == pygame.QUIT: pygame.quit() sys.exit() pygame.event.clear(eventtype = pygame.MOUSEBUTTONDOWN) These do not work pygame.event.clear(eventtype = pygame.MOUSEBUTTONDOWN) for event in pygame.event.get(exclude=[pygame.MOUSEBUTTONDOWN]): if event.type == pygame.QUIT: pygame.quit() sys.exit() and for event in pygame.event.get(exclude=[pygame.MOUSEBUTTONDOWN]): if event.type == pygame.QUIT: pygame.quit() sys.exit() pygame.event.clear(eventtype = pygame.MOUSEBUTTONDOWN) . Does anyone have an idea of why this happens? I already tried to ask AIs, but they kept giving me clearly wrong answers. When i put pygame.event.clear just after the for loop, wouldn't it be called right at the end of the for loop, just like it would have happened if it was inside it? Continue reading...