问题
I'm making a multiplayer platformer/shooter/brawl game with pygame and I'd like for the players to easily change their keybinds (such as from a config file).
I haven't been able to find a way to read a character string and use that as a transition to the pygame.K_xx
objects as of now so I ask the community.
Any leads ?
回答1:
With the constants of this list you can use
getattr(pygame, 'K_'+ mychar)
to access a constant by name.
来源:https://stackoverflow.com/questions/46714719/pygame-get-key-object-from-character