|
|
发表于 2020-2-15 22:33:39
|
显示全部楼层
百度来的,修改了一点,写了个无限循环不断接收键盘输入,按一个按键立即有反应,只能帮你到这了:
- class _Getch:
- """Gets a single character from standard input. Does not echo to the
- screen."""
- def __init__(self):
- try:
- self.impl = _GetchWindows()
- except ImportError:
- self.impl = _GetchUnix()
- def __call__(self): return self.impl()
- class _GetchUnix:
- def __init__(self):
- import tty, sys
- def __call__(self):
- import sys, tty, termios
- fd = sys.stdin.fileno()
- old_settings = termios.tcgetattr(fd)
- try:
- tty.setraw(sys.stdin.fileno())
- ch = sys.stdin.read(1)
- finally:
- termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
- return ch
- class _GetchWindows:
- def __init__(self):
- import msvcrt
- def __call__(self):
- import msvcrt
- return msvcrt.getch()
- while True:
- getch = _Getch()
- a = getch()
- if(a == "3"):
- print("yes")
- else:
- print("no")
复制代码
文章地址:
https://blog.csdn.net/chent86/article/details/76733655 |
|