- 論壇徽章:
- 0
|
本帖最后由 xu_liuzhen 于 2013-04-25 15:53 編輯
用這個(gè)鏈接的方法獲取鍵盤輸入(方法程序在這里),- import select
- import sys
- import time
- import os
- import termios
- def kbhit():
- fd = sys.stdin.fileno()
- r = select.select([sys.stdin],[],[],0.01)
- rcode = ''
- if len(r[0]) >0:
- rcode = sys.stdin.read(1)
- return rcode
- fd = sys.stdin.fileno()
- old_settings = termios.tcgetattr(fd)
- new_settings = old_settings
- #new_settings[3] = new_settings[3] & ~termios.ISIG
- new_settings[3] = new_settings[3] & ~termios.ICANON
- new_settings[3] = new_settings[3] & ~termios.ECHONL
- print 'old setting %s'%(repr(old_settings))
- termios.tcsetattr(fd,termios.TCSAFLUSH,new_settings)
- while True:
- c = kbhit()
- if len(c) !=0 :
- print 'K %s'%(c)
- else:
- print 'Sleep 1'
- time.sleep(1)
復(fù)制代碼 自己寫小程序測(cè)試沒有問(wèn)題,添加到其他程序里就報(bào)錯(cuò):
r = select.select([sys.stdin],[],[],0.01)
AttributeError: 'function' object has no attribute 'select'
還請(qǐng)大神們指點(diǎn)指點(diǎn) |
|