def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
# restore behavior for special things
if ch == '\x03': # ^C
raise KeyboardInterrupt
elif ch == '\x1a': # ^Z
os.kill(os.getpid(), signal.SIGTSTP)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
评论列表
文章目录