Ale865
Ale865

Reputation: 126

Pygame keyboard input doesn't works - Python

Can someone help me ? When i press - A - on the keyboard , nothing happen

import pygame
pygame.init()

pygame.display.set_caption("PyGame")
pygame.display.set_mode((640,480))


while (True): 
    for event in pygame.event.get():
        if (event.type == pygame.K_a):
            pygame.quit()

Upvotes: 1

Views: 70

Answers (1)

Arkadiusz Drabczyk
Arkadiusz Drabczyk

Reputation: 12383

That should work:

#!/usr/bin/env python3

import pygame
import sys


pygame.display.set_caption("PyGame")
pygame.display.set_mode((640, 480))
pygame.init()

while (True):
    for event in pygame.event.get():
         if event.type == pygame.KEYDOWN:
            if (event.key == pygame.K_a):
                pygame.quit()
                sys.exit(0)

Upvotes: 2

Related Questions