Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make it so the key I press assigns itself to a variable. Like so I would click s and the variable would equal "s". How would I do this?

What I have tried:

if keys[pygame.K_q]:
                letter1 = "Q"

I don't want to do this for all 26 letters because it's very inefficient.
Posted
Updated 4-Jul-21 21:25pm

You wouldn't use 26 different variables to hold these values you click. You would normally use an array to hold the values.

I'd be more specific, but your question isn't very clear about what you're doing.
 
Share this answer
 
You should study the Pygame documentation to see how it handles keyboard input: Pygame Front Page — pygame v2.0.1.dev1 documentation[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900