50982

Pygame, get key object from character

Question:

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 ?

Answer1:

With the constants of <a href="https://www.pygame.org/docs/ref/key.html" rel="nofollow">this list</a> you can use

getattr(pygame, 'K_'+ mychar)

to access a constant by name.

Recommend

  • Syntax Errors in QuizGame and Tips [closed]
  • Why do DirectX fullscreen applications give black screenshots?
  • Accessing instantiated object from another class - c#
  • Uploading entity with parent using bulkloader
  • System.IO.Directory.GetFiles. No definition for GetFiles?
  • Android: Time calculations, how to add a specified amount of minutes
  • Launch Internet explorer from xna game on WP7
  • Arabic text displaying in webapp without db changes
  • Is it possible to utilize $addToSet multiple times in the same update?
  • SPARQL queries doesn't works without LIMIT clause
  • How can I see all the files that were modified/added/removed in the last push received?
  • Gradle - How to detect --debug flag from command line?
  • how to sort an arraylist that contains string arrays?
  • HTTP Module intercept requests and breaks custom errors configuration
  • How to bind comma separated list of values to List
  • Tinymce strips attributes on submit
  • Create a multiple screen android application
  • Jquery UI Sortable, move item automatically
  • apply a javascript function to draggable copy
  • Aptana 3 remove bundle (jquery)
  • netsh acl setting (need alternative method - registry settings?)
  • jQuery: add elements until a particular height is reached
  • uml Composition relationships to RDF and OWL
  • Azure table store snapshot/backup capability
  • xtable package: Skipping some rows in the output
  • Change JButton Shape while respecting Look And Feel
  • Adding custom controls to a full screen movie
  • Calling of Constructors in a Java
  • Circular dependency while pushing http interceptor
  • Traverse Array and Display in markup
  • Transpose CSV data with awk (pivot transformation)
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • coudnt use logback because of log4j
  • python draw pie shapes with colour filled
  • Is there any way to bind data to data.frame by some index?
  • How can i traverse a binary tree from right to left in java?
  • UserPrincipal.Current returns apppool on IIS