-1

I'm creating a very simple aplication in pygame which only does one thing, detect if I pressed my up key, down key, enter key or backspace key. If I press any other key, then it will print that I pressed a different key than those mentioned.

The problem is that when I press either my enter or backspace, it will print me I pressed other key rather than my enter / backspace key. So pygame DOES recognise I'm pressing this keys but still, it won't assign that press to the keys I want.

Maybe I'm forgetting to code something important but I can't seem to make it work. Any help is pretty much appreciated, thanks!

EDIT: I'm using pygame 2.0.1 and python 3.9.3

pygame.init()
running = True

screen = pygame.display.set_mode([720, 480])

while running:
    for event in pygame.event.get():

            if event.type == pygame.QUIT:
                running = False
            
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    print("Up key was pressed.")
                    

                elif event.key == pygame.K_DOWN:
                    print("Down key was pressed.")
                    

                elif event.type == pygame.K_RETURN:
                    print("Enter was pressed.")
                    

                elif event.type == pygame.K_BACKSPACE:
                    print("Backspace was pressed.")

                else:
                    print("Another different key was pressed")
                    


Nyktein
  • 15
  • 4

0 Answers0