python 监听键盘输入

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

猜你喜欢

转载自www.cnblogs.com/sea-stream/p/11210288.html
今日推荐