我想要一个脚本,将返回按键一旦用户按下即使它有时间限制。我使用时间限制让用户输入返回,但我的代码无法工作。我尝试了以下方法。在
def answer(timeout):
print "Enter the answer"
stop = time.time() + timeout
r=['a','b','c','d']
while True:
if msvcrt.getche() in r:
return msvcrt.getche()
else:
if time.time() > stop:
return 'O'
但在超时前我只能得到“ÿ”,即使我按下任何键,也不会被检测到。 这里我需要一个代码,当按下时返回a | b | c | d,当时间超过时返回O。在
目前没有回答
相关问题 更多 >
编程相关推荐