Measuring key lift time relative to stimulus onset

Hi @Becca ,

I am having some trouble trying to record key press durations using #builder and was wondering if you’d be able to help?

In my experiment, participants need to type a word they see on screen, and I want to record the key press duration of each key they press.

I have tried adding the following into a code component in my routine:

Begin Routine

duration=[]
kb = keyboard.Keyboard()

Each Frame

keys2 = kb.getKeys()
for key in keys2: 
    if key.duration:
        duration.append(key.duration)

End Routine

trials.addData("Hold Times", duration)

When I run the experiment, I get the column in the .xlsx file called ‘Hold Times’ but in the first row I just get ‘’ and nothing inside the list. It seems to me that nothing is actually getting appended to the list ‘duration’ but I can’t figure out why. I have also tried using ‘thisKey’ instead of ‘key’ in the ‘Each Frame’ code to no avail.

As FYI, I am using PsychoPy v2020.2.1 Standalone in Windows 10 and will need to push the experiment to Pavlovia in the future.

Here is my experiment if that helps: StudentExperiment_counterbalanced.psyexp (96.3 KB)

Any help would be hugely appreciated!