国产探花免费观看_亚洲丰满少妇自慰呻吟_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 獲取鍵盤輸入,同時有超時的功能示例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海晏县| 双鸭山市| 黄冈市| 乌审旗| 聂荣县| 汤原县| 霸州市| 贞丰县| 怀远县| 卢氏县| 忻城县| 陇川县| 宝兴县| 蒙自县| 旬阳县| 彰化市| 秀山| 洪湖市| 云和县| 尼木县| 牙克石市| 杭锦后旗| 阿瓦提县| 原阳县| 博乐市| 买车| 文成县| 贵港市| 黄陵县| 宣武区| 乌兰察布市| 红原县| 德清县| 渭源县| 蓬溪县| 郓城县| 平和县| 新邵县| 德庆县| 中超| 花莲市|