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

首頁 > 編程 > Python > 正文

python監控鍵盤輸入實例代碼

2020-02-22 23:11:27
字體:
來源:轉載
供稿:網友

本文研究的主要是python監控鍵盤輸入的相關代碼,用到了os,sys,time等,具體實現代碼如下:

#!/usr/bin/env python  # -*- coding: utf-8 -*- import os  import sys import tty, termios import time    if __name__ == '__main__':   print "Reading form keybord"   print """  i j k l   m"""   print 'press Q to quit'   while True:     fd=sys.stdin.fileno()     old_settings=termios.tcgetattr(fd)     #old_settings[3]= old_settings[3] & ~termios.ICANON & ~termios.ECHO      try:       tty.setraw(fd)       ch=sys.stdin.read(1)     finally:       termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)        #print 'error'     if ch=='i':       print 'move forward'     elif ch=='m':       print 'move back'     elif ch=='j':       print "turn left!"     elif ch=='l':       print "turn right!"     elif ch=='u':       print "turn right!"     elif ch=='o':       print "turn right!"     elif ch=='k':       print "stop motor!"     elif ch=='q':       print "shutdown!"       break     elif ord(ch)==0x3:       #這個是ctrl c       print "shutdown"       break     print "Reading form keybord"     print """  i j k l   m"""     print 'press Q or ctrl+c to quit'     #rate.sleep() 

結果:

總結

以上就是本文關于python監控鍵盤輸入實例代碼的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續參閱本站其他相關專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汕尾市| 涟水县| 牡丹江市| 屏东市| 丘北县| 汾西县| 冕宁县| 乡宁县| 乌拉特前旗| 武清区| 绵阳市| 宜川县| 金阳县| 德阳市| 平度市| 修武县| 六安市| 乌审旗| 静安区| 西昌市| 德化县| 许昌县| 班玛县| 汨罗市| 象山县| 韩城市| 青州市| 清涧县| 海林市| 德格县| 廊坊市| 德兴市| 霍林郭勒市| 射洪县| 伽师县| 香格里拉县| 白玉县| 尤溪县| 永吉县| 峨边| 中山市|