How to hold a ‘key down’ in Pygame?

pygame.key.get_pressed() is a function form pygame.key module. It returns a list of boolean values representing the state of every key on the keyboard.

If you want to test if the SPACE key is pressed the you have to get the state of K_SPACE by subscription:

keys = pygame.key.get_pressed() 
if keys[pygame.K_SPACE]:
    # [...]

Leave a Comment