pygame key press once code example
Example 1: pygame key pressed once
pressed = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_a and not pressed:
pressed = True
elif event.key != pygame.K_a:
pressed = False
Example 2: pygame keys keep pressing
while not done:
for e in event.get():
if e.type == KEYDOWN:
keys = key.get_pressed()
if e.type == QUIT or keys[K_ESCAPE]:
done = True
if keys[K_DOWN]:
print "DOWN"
Example 3: pygame keys keep pressing
while not done:
for e in event.get():
if e.type == KEYDOWN:
keys = key.get_pressed()
if e.type == QUIT or keys[K_ESCAPE]:
done = True
while keys[K_DOWN]:
print "DOWN"
event.get()
keys = key.get_pressed()