Toby Walter
Toby Walter

Reputation: 1

How do I make python react to something in the console (without pressing enter)

I am making a game in python, but I want python to react to the W,A,S,D keys without pressing enter. Like:

If w in console: Y_pos = Y_pos + 1

If you guys could tell me how to do that then that would be a big help

Upvotes: 0

Views: 621

Answers (2)

Yayong Duan
Yayong Duan

Reputation: 59

Maybe keyboard package is what you need. Various usages for your information.

keyboard usages

Upvotes: 1

FlyingPlushie
FlyingPlushie

Reputation: 68

Take a look at some of the answers here. In general, you need an infinite while loop that will accept the user input. Don't forget an exit condition, otherwise you'll have to kill the program to end it.

If you're doing this for practice, kudos. But, in case you're focused on making a working game, not on python itself, may I suggest pygame engine for starters?

Upvotes: 1

Related Questions