Reaction time between stimulus onset and event.waitkeys

101 views
Skip to first unread message

m.t....@student.rug.nl

unread,
Jan 31, 2016, 8:24:08 AM1/31/16
to psychopy-users
Hello,

I have a question.

I have a stimulus say,

win =  visual.Window([1300,650], color= 'black', units = 'pix')
stim =  visual.TextStim(win, text='stimulus', height=18, color='white',pos=[0,-0] )
stim.draw()
number_resp_key = event.waitKeys(keyList=['1', '2', '3',])
win.flip()

How can I record the reaction time between the stimulus onset and the key press made by the participant? 
Is there any coding for it?

Thanks very much for answering my question,
Marco

Michael MacAskill

unread,
Jan 31, 2016, 3:41:58 PM1/31/16
to psychop...@googlegroups.com
Hi Marco,

You haven't quite got the order of events right here: the stimulus won't appear until win.flip() has completed, so the .waitKeys() call has to come after that.

There are a number of timing demos under the "Demos" menu in the Coder view. But something like this could work for you:

win = visual.Window([1300,650], color= 'black', units = 'pix')
stim = visual.TextStim(win, text='stimulus', height=18, color='white',pos=[0,-0] )
timer = core.Clock() # just need to create this once

stim.draw() # send the stimulus to the back buffer
win.flip() # actually display the stimulus

timer.reset() # zero the clock from the moment the stimulus has been displayed
number_resp_key = event.waitKeys(keyList=['1', '2', '3',])
rt = timer.getTime() # the time elapsed

Note that you can also send a clock to the waitKeys function so that the keypresses are returned automatically with a time stamp attached:

timer.reset() # zero the clock (if desired).
number_resp_key = event.waitKeys(keyList=['1', '2', '3',], timeStamped=timer) # now returns keys & times


But note that by using waitKeys, you are no longer synchronising with the screen refresh cycle. That may or may not be important to you. i.e. an alternative is to have a loop which calls win.flip() on every iteration followed by a call to event.getKeys(). Rather than waiting for a response, this just checks the instantaneously for any keypresses since the last time it was called.

Regards,

Michael
--
Michael R. MacAskill, PhD 66 Stewart St
Research Director, Christchurch 8011
New Zealand Brain Research Institute NEW ZEALAND

Senior Research Fellow, michael....@nzbri.org
Te Whare Wānanga o Otāgo, Otautahi Ph: +64 3 3786 072
University of Otago, Christchurch http://www.nzbri.org/macaskill

m.t....@student.rug.nl

unread,
Feb 1, 2016, 5:11:46 AM2/1/16
to psychopy-users
Dear Michael,

Thanks very much for your great help.

It works now thanks to you!

Have a good start into the new week,
Marco
Reply all
Reply to author
Forward
0 new messages