我正在使用评分量表。参与者使用“'和' b'键沿着刻度移动光标。每个试验目前为6秒。如果参与者停止按下' t'或者' b'在6秒之前,我想在日志文件中记录最后一次按键的时间。但是,我不知道如何检查哪个按键是最后一个。我正在考虑记录列表中最后一个按键的RT,但代码正在检查每次刷新时的按键。这就是我到目前为止所做的:
trialNum=0
for eachPic in catPictures:
prevPos = 0
key=[]
b_list=[]
t_list=[]
timer = core.CountdownTimer(TrialDuration)
event.clearEvents() # get rid of other, unprocessed events
while timer.getTime() > 0:
for key in event.getKeys():
if key in ['escape']:
core.quit() # quit if they press escape
if key in ['b']:
# add keypress to list for each keypress. then move cursor proportionally to length of this list
b_list.append(key)
prevPos+=len(b_list)
if key in ['t']:
t_list.append(key)
prevPos-=len(t_list)
答案 0 :(得分:2)
while
循环中的内容。psychopy.visual.RatingScale
的建议(此问题的另一个答案)。未经测试的代码:
timer = core.CountdownTimer(TrialDuration)
stepSize = 1
for eachPic in catPictures:
prevPos = 0 # keeps track of the slider position
rts=[] # used to keep track of what the latest reaction time was. Reset in the beginning of every trial.
timer.reset()
event.clearEvents() # get rid of other, unprocessed events
while timer.getTime() > 0:
for key, rt in event.getKeys(timeStamped=timer): # time keys to this clock
rts += [rt] # add this reaction time to the list
if key in ['escape']:
core.quit() # quit if they press escape
if key in ['b']:
# add keypress to list for each keypress. then move cursor proportionally to length of this list
prevPos+=stepSize
if key in ['t']:
prevPos-=stepSize
# Log here instead of print
print rts[-1]
答案 1 :(得分:2)
对于给定的评定量表rs,在试验期间和之后,rs.history中都可以获得所有受试者的活动。历史只是一个元组列表,每个元组都是(等级,时间)。如果比例已经开始,则第一个元组始终为(None,0.0)。如果最后两个评级相同,则主题接受该评级。如果它们不同,则主题在规模上移动但在规模超时时未接受评级。
示例历史记录: [(无,0.0),(3,0.777),(3,1.396)]
from psychopy import visual, core
win = visual.Window()
rs = visual.RatingScale(win)
c = core.CountdownTimer(3)
while c.getTime() > 0:
rs.draw()
win.flip()
# print or log:
print rs.history # entire history
print rs.history[-1][1] # just the time of the last rating