Python在输入时设置等待时间的一种方法

Python在输入时设置等待时间的一种方法

# -*- coding: utf-8 -*-
"""
@author: __spyder__
"""
import  time
import  msvcrt
import  os

def getInput( timeout = 5):
    start_time = time.time()
    input = ''
    while True:
        if msvcrt.kbhit():
            input = msvcrt.getche()
        if len(input) != 0 or (time.time() - start_time) > timeout:
            break
    if len(input) > 0:
        return ord(input)
    else:
        return ord('\0')
        
print(getInput(5))
os.system("pause")

猜你喜欢

转载自blog.csdn.net/weixin_38604589/article/details/89295922
今日推荐