I have an experiment in which participants are shown a visual metronome (pulsating dot). I created a routine for the stimulus presentation, which is part of a loop. Participants are asked to press a key each time they see the dot. At the beginning of the routine I inserted a code component to write the reaction times, the variable of interest, to a data file.
This works fine, as long as participants press the key within the time window of 1 routine since in Builder the clock gets reset after each routine. What I would like to see is the clock being reset only if a key is pressed. So, each data point is then the elapsed time since the last keypress, independent of stimulus presentation.
I created a separate clock (see code below) but this attempt was not successful yet.
Many thanks for every insight!
# define clock to time keypresses testClock = core.Clock()
# collect keys keys = event.getKeys() if keys: if 'k' in keys: RT = testClock.getTime() thisExp.addData('RT in ms', RT*1000) testClock.reset()