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?