#🔒 keyboard module leaving key strokes in input()
20 messages · Page 1 of 1 (latest)
@worn summit
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
keyboard module leaving key strokes in input()
you probably want to flush the input stream somehow, before asking for input. I found this relevant stackoverflow post mentioning it, and one answer seems to be simply sys.stdin.flush(), so try that I guess?
@worn summit pinging you because it's been a while of inactivity
I can't get it working right now but I'll read some documentation on it because I probably don't understand what it does/how to use it
No matter where i put the sys.stdin.flush() i cant get it working.
i think it might be because of how the keyboard module works
result with
import sys
from time import sleep
import keyboard
while True:
sleep(0.2)
user_input = keyboard.read_key()
print(user_input)
if user_input == 'esc':
sys.stdin.flush()
break
input('a ')
i'll just use a different module
oh I guess I misexplained it. The idea would be that just before calling input, you'd flush the stdin, like so:
... #game happening here
exit_game() # or however you do it
sys.stdin.flush() #flush here so keys pressed during the game aren't read by input in stdin
input() #ask for input outside the game
```that way, any already pressed keys would be "read" and not show up after you left the game. The inputs would still, however, be read, so pressing Ctrl + C or something still causes the program to exit
huh, that's interesting
I don't really know what to do then. maybe check out the post I linked and see if something magically works :)
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.