gpt4 book ai didi

python - Psychopy:如何让参与者使用键盘上的特定键做出响应。蓝色=f?

转载 作者:太空宇宙 更新时间:2023-11-03 15:25:13 32 4
gpt4 key购买 nike

目前我有代码:

import random
from psychopy import visual, event
win = visual.Window()

# A TextStim and five of each word-color pairs
stim = visual.TextStim(win)
pairs = 5 * [('blue', 'blue'), ('yellow', 'blue'), ('green', 'yellow'), ('red','red')]
random.shuffle(pairs)

# Loop through these pairs
for pair in pairs:
# Set text and color
stim.text = pair[0]
stim.color = pair[1]

# Show it and wait for answer
stim.draw()
win.flip()
event.waitKeys()

我试图将键盘上的键“f”分配给红色,“g”分配给蓝色,“h”分配给黄色,“j”分配给绿色,因此当参与者看到时按下“f”红色,我想记录 react 时间,我希望它说“正确”或“不正确”?我已经尝试了很多代码,但我认为我把它们放在错误的顺序或者我去错了地方!

最佳答案

实现此目的的一个巧妙方法是使用 python 字典作为键含义映射。所以一开始就定义

answer_keys = {'f': 'red', 'g': 'blue', 'h': 'yellow', 'j': 'green'}

作为一个简单的演示,然后

answer_keys['f'] == 'blue'  # False
answer_keys['g'] == 'blue' # True

要在实验中使用它,请执行以下操作:

# Get answer and score it, and get RT
key, rt = event.waitKeys(keyList=answer_keys.keys(), timeStamped=True)[0] # Only listen for allowed keys. [0] to get just first and only response
score = answer_keys[key] == pair[1] # Whether the "meaining" of the key is identical to the ink color of the word.

# Show feedback
stim.text = 'correct' if score else 'incorrect' # show text depending on score
stim.text += '\nRT=%i ms' %(rt*1000) # Add RT to text, just for demo
stim.draw()
win.flip()
event.waitKeys() # Wait, just to leave it on the screen for a while.

关于python - Psychopy:如何让参与者使用键盘上的特定键做出响应。蓝色=f?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43214406/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com