import sys, select, tty, termios old_attr = termios.tcgetattr(sys.stdin) tty.setcbreak(sys.stdin.fileno()) print('Please input keys, press Ctrl + C to quit') while(1): if select.select([sys.stdin], [], [], 0)[0] == [sys.stdin]: print(sys.stdin.read(1)) termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_attr)
参考:
https://blog.csdn.net/NiYintang/article/details/86116591