0

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

2 Answers2

1

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?

FlyingPlushie
  • 68
  • 1
  • 7
1

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

keyboard usages

  • You can improve your answer by adding some more explanation and code. – Zahra Feb 18 '22 at 14:24
  • Package keyboard needs to be run in a root privilege. But my local env was restricted as normal user, only have remote server with root privilege. Sorry for the answer without validation. – Yayong Duan Feb 19 '22 at 08:45