我有一个python代码,理想情况下应该在键入单词或字符时测量飞行和停留时间。就我而言,我输入:.zoroBen1。
代码:
def captureKey():
global c, flight_elapsed, Td, inputstr, dwell_elapsed, index, Tf
while '\n' not in inputstr:
c = getch();
print "Character: " , c
# This list stores the fight time
flight_elapsed.append(time.time() - Td)
inputstr += c
Tf = time.time()
index += 1
# Due to the way the program is written, the first value of the dwell
# list and flight list are not useful
del(dwell_elapsed[0])
del(flight_elapsed[0])
def getch(inp=sys.stdin):
global flight_elapsed, Td, inputstr, dwell_elapsed, index, Tf
old = termios.tcgetattr(inp)
new = old[:]
new[-1] = old[-1][:]
new[3] &= ~(termios.ECHO | termios.ICANON)
new[-1][termios.VMIN] = 1
try:
termios.tcsetattr(inp, termios.TCSANOW, new)
Td = time.time()
dwell_elapsed.append(time.time() - Tf)
return inp.read(1)
finally:
termios.tcsetattr(inp, termios.TCSANOW, old)
当我运行程序时,flight_elapsed数组的内容大小为0.1(值为0.52,0.11等),但dwell_elapsed数组的值大约为10 ^( - 5)(值类似1.2 * 10 ^( - 5)等。)
我是否正确计算了飞行/停留时间?或者是否有错误,因为我不确定停留时间是否应该是这么低。