| Reference | Downloads | Github

Recording reaction time

Dear community,

I am currently programming my first experiment which you can see below. The participant should react as fast as possible to the words displayed and I want to record the reaction time between displaying the word to the participant reacting by pressing the space key. I already tried several things but so far, it only records the time without setting it back after each trial. I believe it should work with clearEvents, but hasn’t worked so far, so I would be very grateful for any help!

from psychopy.visual import Window, TextStim, RatingScale
from psychopy.core import wait, Clock
from psychopy.event import waitKeys, getKeys, clearEvents
import random

wordlist = [‘murder’, ‘death’, ‘raped’, ‘fight’, ‘drown’, ‘wound’, ‘lynch’, ‘choke’, ‘angel’, ‘sugar’, ‘dream’, ‘ocean’, ‘green’, ‘music’, ‘marry’, ‘sleep’]

my_win = Window( [800, 500], color=‘black’)

welcome_text = TextStim ( my_win, text = “Welcome to this psychological experiment. Your task is to respond to a word which is presented by pressing the ‘space’ key as fast as possible.” )

cross_1 = TextStim ( my_win, text = ‘+’ )

waitKeys( keyList = [‘space’] )

for words in wordlist:
task_1 = TextStim ( my_win, text = random.choice(wordlist))

wait( 2 )

response = waitKeys(timeStamped = True, clearEvents = True)

scale_1 = RatingScale ( my_win, scale = "How do you rate the valence of this word?", labels = ("positive", "negative"), marker = "slider", mouseOnly = True )

while scale_1.noResponse:
    rating = scale_1.getRating()
print(rating, response)

end_text = TextStim ( my_win, text = “Thank you for participating in this experiment! This is a valuable contribution to the scientific community.” )

You might be better off using a Keyboard component for this; provided the component starts at the same time as the stimulus, you can get a list of keys pressed by using keyboardComponent.getKeys(), if you then iterate through this list each key will have a property called rt which is a measure of how long it took the participant to respond.