Record multiple response times

I’m trying to modify my code so that I can record multiple response times. I know that the builder does this automatically, but I have a certain time restraints coded so that the trial ends at 2s if the participant responds before 2s. I have the correct code for recording multiple keys, but I need one for recording multiple response times.

I tried to modify the code below by using the same one that I have for multiple keys (for key in keys) to one for multiple RTs (for t in ts, etc.). This did not work. Is there a way that I can record multiple RTs and have them automatically separated by a comma in Excel?

The current code is below.

'
if t >= 2.0 and end_at_2s:
continueRoutine = False
elif t >= 4.0: # all trials end at this stage
continueRoutine = False

otherwise, check for a new keypress:

keys = event.getKeys()

if keys: # if at least one key exists in the list,
if ‘escape’ in keys: # now need to check for the quit key ourselves
core.quit()

elif t < 2.0: # just remember this for later
    if not end_at_2s:
        thisExp.addData('RT_A', t)
        end_at_2s = True 

for all key presses:

    for key in keys:
        keys_pressed = keys_pressed + key # concatenate multiple keys
    thisExp.addData('answer', keys_pressed) # update the data

else: # we have a keypress between 2 and 4 s
    thisExp.addData('RT_A', t)
    thisExp.addData('answer', keys)
    continueRoutine = False'

I can’t test this out based on the codes you provided, and not exactly sure of the context, but assuming your t is an active timer that goes from 0.0 to 2.0, my guess would be that changing:-

for key in keys:
    keys_pressed = keys_pressed + key # concatenate multiple keys
thisExp.addData('answer', keys_pressed) # update the dat

to this

    for key in keys:
        keys_pressed = keys_pressed + key # concatenate multiple keys
        timeList.append(t)
    thisExp.addData('answer', keys_pressed)
    thisExp.addData('time of answer', timeList) # update a list of time for each key presses to the column 'time of answer', which I assume if what you intend to record? The order of this should correspond to the keys pressed.

You need to add timeList = [] at the start of your script as well.

Thank you! This works.