国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python 獲取鍵盤輸入,同時有超時的功能示例

2020-02-15 23:39:17
字體:
來源:轉載
供稿:網友

如下所示:

'''###get keyboard input and timeout =5import sys, time, msvcrtdef readInput( caption, default, timeout = 5): start_time = time.time() sys.stdout.write('%s(%s):'%(caption, default)); input = '' while True:  if msvcrt.kbhit():   chr = msvcrt.getche()   if ord(chr) == 13: # enter_key    break   elif ord(chr) >= 32: #space_char    input += chr  if len(input) == 0 and (time.time() - start_time) > timeout:   break print '' # needed to move to next line if len(input) > 0:  return input else:  return default  readInput("TEst1",10)'''###catch keyboard input, if key == ESC, stop import sys, time, msvcrtdef readKeyBoardInput(timeout = 5): start_time = time.time() sys.stdout.write("If you want to stop test process,please click ESC button"); input = '' while True:  if msvcrt.kbhit():   chr = msvcrt.getche()   if ord(chr) == 27: # ESC    return True  if len(input) == 0 and (time.time() - start_time) > timeout:   return False

以上這篇python 獲取鍵盤輸入,同時有超時的功能示例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 清徐县| 青海省| 大竹县| 错那县| 抚州市| 武夷山市| 扎兰屯市| 湾仔区| 南康市| 漳州市| 蒲江县| 普定县| 麻栗坡县| 高阳县| 偏关县| 兰州市| 都安| 台中县| 彰化县| 新蔡县| 龙泉市| 鲜城| 类乌齐县| 盐边县| 吴旗县| 三明市| 永德县| 商水县| 汉中市| 平泉县| 大城县| 清苑县| 兴安县| 江源县| 黑河市| 湘潭县| 灵丘县| 靖江市| 蒲城县| 长顺县| 富锦市|