1import pygame
2events = pygame.event.get()
3for event in events:
4 if event.type == pygame.KEYDOWN:
5 if event.key == pygame.K_LEFT:
6 location -= 1
7 if event.key == pygame.K_RIGHT:
8 location += 1
9
1# Outside loop
2pressed = False
3
4# Inside loop
5if event.type == pygame.KEYDOWN:
6 if event.key == pygame.K_a and not pressed: #K_a can be replaced by any key
7 # Do something
8 pressed = True
9 elif event.key != pygame.K_a:
10 pressed = False