# Chapter 33 try-this: print the name of each key pressed. # # In the event loop, add a KEYDOWN handler that prints # f"pressed: {pygame.key.name(event.key)}". pygame.key.name(key) converts a # key constant to a human-readable string like "left" or "space". Run the # program and press several keys. # # Run with: python exercises/33/01-print-key.py import pygame pygame.init() screen = pygame.display.set_mode((800, 600)) pygame.display.set_caption("Print Key") clock = pygame.time.Clock() running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # TODO: add the KEYDOWN handler here screen.fill((30, 30, 30)) pygame.display.flip() clock.tick(60) pygame.quit()