Reputation: 189
I am trying to loop round all of the number keys on a keyboard (0-9) and thought to do this you would use this code:
for i in range (0,10):
if keys[pygame.K_i]:
pass
But obviously as expected, pygame.K_i treats 'i' as the keyboard input 'i' not the variable. I was wondering how to specify I would like to use the variable not the keyboard input.
Sorry if the title is misleading, thanks.
Upvotes: 1
Views: 48
Reputation: 20438
The key constants (like pygame.K_0
) are just integers that represent the keyboard keys. pygame.K_0
is 48, pygame.K_1
is 49 and so on. You can use the range range(48, 58)
.
Upvotes: 2