Skip to content
← Back to Community
[Python] How do I input without pressing enter
Profile icon
xolyon

input("> ") requires the user to enter for input
how can I just make them type something and then for it to instantly process?

Answered by Roar123 [earned 5 cycles]
View Answer
Voters
Profile icon
TACO711
Profile icon
Kadenzaa
Profile icon
multicoder2021
Profile icon
AustinMasoodi
Profile icon
xolyon
Comments
hotnewtop
Profile icon
Roar123

Getkey is the best and easiest solution for this specific problem. Here's an example from their PyPI description.

from getkey import getkey, keys key = getkey() if key == keys.UP: ... # Handle the UP key elif key == keys.DOWN: ... # Handle the DOWN key elif key == 'a': ... # Handle the `a` key elif key == 'Y': ... # Handle `shift-y` else: # Handle other text characters buffer += key print(buffer)
Profile icon
xolyon

@Roar123 cool so does this work for wasd?

Profile icon
Roar123

@xolyon Definitely, just check if key == 'w': for any character keys. For arrow keys, use keys.____ with your direction in the blank, ex. keys.DOWN.

Profile icon
CodeLongAndPros

@xolyon I would say yes, just replace the keycodes.

Profile icon
xolyon

@Roar123 I figured that out by now but thanks

Profile icon
Roar123