import pygame

# Initialisation de pygame
pygame.init()

# Création de la fenêtre
WIDTH, HEIGHT = 500, 300
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Affichage des touches")

# Définition des couleurs
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)

# Police d'écriture
font = pygame.font.Font(None, 36)

running = True
key_name = "Appuyez sur une touche"

# Liste des touches pygame
key_dict = {getattr(pygame, i): i for i in dir(pygame) if i.startswith("K_")}

while running:
    screen.fill(WHITE)
    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN:
            key_name = key_dict.get(event.key, f"Code: {event.key}")
    
    # Rendu du texte
    text_surface = font.render(key_name, True, BLACK)
    text_rect = text_surface.get_rect(center=(WIDTH // 2, HEIGHT // 2))
    screen.blit(text_surface, text_rect)
    
    pygame.display.flip()

pygame.quit()
