1
for event in pygame.event.get():
    if event.type == pygame.KEYDOWN or event.type == pygame.KEYUP:
        print (event)

When I pressed arrow up this was the output:

<Event(2-KeyDown {'unicode': '', 'key': 273, 'mod': 0, 'scancode': 111})>

What is the syntax to access the dict? I want just to print the key key value from this dict. Any ideas?

1 Answer 1

6

To get the value of the key that triggered the pygame.KEYDOWN event, just use event.key to get the value. Currently you're printing the pygame.Event object, but not the key of the event. Try the following:

for event in pygame.event.get():
    if event.type == pygame.KEYDOWN or event.type == pygame.KEYUP:
        print(event.key)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.