getkey
Ulli Horlacher
framstag at rus.uni-stuttgart.de
Sat Jan 16 10:12:25 EST 2016
Ulli Horlacher <framstag at rus.uni-stuttgart.de> wrote:
> The first byte of an escape sequence (example: ^[[21~ for F10) is
> recognized, but the trailing bytes then are not discarded by
> clear_keyboard_buffer() and get_key() returns the second byte of the
> escape sequence.
I have found a solution:
def clear_keyboard_buffer():
try:
while msvcrt.kbhit(): msvcrt.getwch()
except:
fd = sys.stdin.fileno()
fcntl_flags = fcntl.fcntl(fd,fcntl.F_GETFL)
fcntl.fcntl(fd,fcntl.F_SETFL,fcntl_flags|os.O_NONBLOCK)
try:
while sys.stdin.read(1): pass
except:
pass
fcntl.fcntl(fd,fcntl.F_SETFL,fcntl_flags)
--
Ullrich Horlacher Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de
Universitaet Stuttgart Tel: ++49-711-68565868
Allmandring 30a Fax: ++49-711-682357
70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/
More information about the Python-list
mailing list