how to check if the space bar is pressed in pygame code example
Example 1: check key pressed pygame
import pygame
events = pygame.event.get()
for event in events:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
location -= 1
if event.key == pygame.K_RIGHT:
location += 1
Example 2: pygame keydown
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
return True