How would I write a Python program that would always be looking for user input. I think I would want to have a variable equal to the input and then something different would happen based on what that variable equaled. So if the variable were “w” then it would execute a certain command and keep doing that until it received another input like “d” Then something different would happen but it wouldn’t stop until you hit enter.
Share
If you want to constantly look for an user input you’ll need multithreading.
Example:
As you’ll see this, will get your messages a little mixed up, something like:
That’s beacuse there are two threads writing to stdoutput at the same time. To sync them there’s going to be need of
lock:Ok, now it’s better:
Notice that you’ll need to press
Enterbefore typing a command to enter in “input mode”.