'How to assign keys to a word
Hello I'm new to programming and I'm having a hard time in giving giving an assigned key to directions.
import random
move = [
"Left!",
"Right!",
"Forward!",
"Backward!",
"Accelerate!",
"Stop!",
]
direction = random.choice(move)
print(direction)
drive = input("[keypad]> ")
What I want to do is for example if the chosen random word is "Left!" then if I click "a" for left then the program would recognize it as correct answer and feed another direction to me.
Any suggestion to my problem would greatly help me. Thank you!
Solution 1:[1]
You'd have to put the input in a loop for it to keep asking the user for the key. There are other ways of getting input without having to use input as that stops your entire program. I recommend looking into the keyboard library for python (https://pypi.org/project/keyboard/)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BaconPants9873 |
