按键后跳转到下一个试用版

问题描述 投票:0回答:1

[在我的实验中,我有10个试验,并且在每个试验中,参与者必须在看到动画中的颜色变化后尽快按下一个键(“空格”)。作为确认按键按下的反馈,我想在按键按下后转到下一个试用版(移至下一个循环迭代)。我试图用breakcontinue在我的代码中实现这个想法,但它不起作用:

for i in range(nTrials):

    # Start with fixation cross 
    fixation.draw()
    win.flip()
    core.wait(2)

    # Play the video for 200 frames 
    for Nframes in range(200):
        optic_flow_movie.draw()
        fixation.draw()
        win.flip()

    # Get Participants responses
    keys = psychopy.event.getKeys(keyList=["space"],timeStamped=clock)

    if (keys[0][0] == 'space') is True:
        break
    else:
        continue

# Take only the timestamps from the variable key and store it in the variable RTs  
RTs = [sublist[1:2] for sublist in keys]                     # This stores only the timestamps
RTs = [item for sublist in RTs for item in sublist]          # This converts from list of lists to a flat list

非常感谢您的帮助!

python events key break psychopy
1个回答
1
投票

尚不完全清楚试验的结构是什么,但是如果要在动画期间监视响应,则对event.getKeys()的调用需要嵌入到绘图循环中(即for Nframes in range(200):中)。这样,您可以在每次屏幕刷新时检查是否有按键按下,以便可以实时暂停动画。

目前,代码显示了整个动画,然后才检查键盘(但每次试用仅检查一次)。无论那里发生了什么,下一个试验都将开始,因为这是主试验循环中的最后一个代码(即for i in range(nTrials):

最后,event模块不推荐使用键盘响应。您应该真正改用较新的Keyboard类以获得更好的性能:

https://www.psychopy.org/api/hardware/keyboard.html

https://discourse.psychopy.org/t/3-ways-to-get-keyboard-input-which-is-best/11184/3

© www.soinside.com 2019 - 2024. All rights reserved.