Ask coding questions

← Back to all posts
Is there a way to detect key presses in repl?
AcidCreaks (4)

So I did some research on how to detect key presses and do certain actions when certain keys are pressed.

And it looked like it worked but when I do it on repl it doesn't. Is it just because I did something wrong or does repl not detect keypresses?

Answered by CodingCactus (4366) [earned 5 cycles]
View Answer
CodingCactus (4366)
from getkey import getkey
if getkey() == "w":
  #move up

The problem with this, is that it will wait until you press something to continue the program

alternately, you can just use pygame which has built in key listeners (i think)