0

How do I read keyboard input without waiting for the user to press Enter?

10th Apr 2020, 4:32 PM
Vivek Bhat
Vivek Bhat - avatar
4 odpowiedzi
+ 2
That almost possible only in a GUI environment, not really in CLI context (there's some specific tricks to workaround with some platforms, but nothing really os agnostic and/or simple)... ... and not at all in sololearn code playground, of course.
10th Apr 2020, 5:25 PM
visph
visph - avatar
+ 3
Actually it is possible, but you'll have to be creative on it. The first option would be to simulate keypress using a library like pyautotui, and set a timer that will press enter key on timeout. The second option would be to use the threading library and create a timed thread.
10th Apr 2020, 11:22 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
A way to do it is to use the ncurses module (standard library) wich is the binding of ncurses c-library (handling cross-platform/terminal advanced terminal output): there's a mode where you can listen for key events ;) https://en.m.wikipedia.org/wiki/Ncurses https://docs.python.org/3/library/curses.html https://docs.python.org/3/howto/curses.html
12th Apr 2020, 1:23 PM
visph
visph - avatar