0

I'm trying to implement a Input Box in python using pygame and I don't quite get how to handle input text. So far I'm aware that there are two ways of handling text input.

Using pygame.key.get_pressed()

keys = pygame.key.get_pressed()

if keys[pygame.K_a]:
    print('a')

Using events

for event in pygame.event.get():
    if event.type == pygame.KEYDOWN:
        if event.key == pygame.K_a:
            print('a')

In Pygame documentation it says that the first method (pygame.key.get_pressed()) is not the proper way to handle entry text, and that you should use events instead.

The thing is that whenever I try to use events the pygame.KEYDOWN event never seems to trigger. No matter if I have a key pressed or not, it never seems to work.

Am I doing something wrong? Or is there any other way I can handle input text?

Mateoglzc
  • 11
  • 2
  • `pygame.event.get` should only be called **once** per frame, as it removes all events every time it's called. You're presumably calling it multiple times, which is why it doesn't seem to work. – Ted Klein Bergman Jul 14 '21 at 16:56

0 Answers0