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?
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.