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

首頁 > 編程 > Python > 正文

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

2020-01-04 14:05:09
字體:
來源:轉載
供稿:網友

如下所示:

'''###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 獲取鍵盤輸入,同時有超時的功能示例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到python教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长兴县| 吉隆县| 陆良县| 东海县| 吉林市| 保山市| 印江| 周口市| 叶城县| 青神县| 林芝县| 平谷区| 溧水县| 沁阳市| 建德市| 洮南市| 英吉沙县| 略阳县| 岑溪市| 饶河县| 海盐县| 三穗县| 襄汾县| 雅江县| 玉林市| 崇阳县| 泽州县| 太湖县| 孙吴县| 安阳县| 双江| 大埔区| 玉门市| 周至县| 黎川县| 闻喜县| 呼和浩特市| 左权县| 临安市| 阿巴嘎旗| 沙洋县|