Ulli Horlacher <frams...@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: horlac...@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/
-- 
https://mail.python.org/mailman/listinfo/python-list
  • getkey Ulli Horlacher
    • Re: getkey Ulli Horlacher

Reply via email to