【问题标题】:how can i get reaction time in python?我如何在 python 中获得反应时间?
【发布时间】:2019-08-23 09:07:34
【问题描述】:

我无法得到正确的反应时间。

以下是我实现它的尝试:

kb = keyboard.Keyboard()
RT = core.Clock()

def run(data):
    trial=0 
    for j in range(1,5):
        for i in data:
            kb.clock.reset()
            excelTrialEq = trial
            print (i)
            myword.text=i[0]
            myword.draw()
            mywin.flip() #draw letter 

            RT.reset()           
            RT.add((0.25) + i[1]
            core.wait(0.25)
            mywin.flip() #draw blank(ISI)

            while RT.getTime() < 0 : pass # wait till end stimulus showing + ISI 

我希望输出像

['M', 1]
1 2 M 1
space, 0.50980908090
...

但实际输出是

['M', 1]
1 2 M 1
['K', 1]
space -0.25774913992427173
...

【问题讨论】:

  • 我认为timeit module 适合您的需求
  • 我没有看到任何平台信息。 Bash、CMD、WIN、LIN、TK、TCL 等!

标签: python keyboard response real-time


【解决方案1】:

从您的代码中并不清楚您想要做什么。但是,如果我理解正确,您会在屏幕上显示一些内容并等待用户按空格键。 最简单的做法是:

import time

#When the item appears on the screen
startTime = time.time()

#When the user presses space
endTime = time.time()

reactionTime = endTime - startTime

【讨论】:

  • 这就是我想要的!但我不知道如何将它准确地应用到我的脚本中。我在屏幕上显示一些字母并等待用户按空格键。但经过一定时间后,试用结束,出现下一个试用。
猜你喜欢
  • 2023-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-15
  • 2021-08-15
  • 2019-02-23
  • 1970-01-01
相关资源
最近更新 更多