- 论坛徽章:
- 0
|
本帖最后由 xu_liuzhen 于 2013-04-25 15:53 编辑
用这个链接的方法获取键盘输入(方法程序在这里),- 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)
复制代码 自己写小程序测试没有问题,添加到其他程序里就报错:
r = select.select([sys.stdin],[],[],0.01)
AttributeError: 'function' object has no attribute 'select'
还请大神们指点指点 |
|