Can't access keyboard response duration

Following a recent paper suggesting that response duration can provide unique information to reaction times, I am trying to record durations. According to the manual, duration should be accessible, but I get messages that its undefined.

Using the following code in ‘Every frame’, I can get the name of the response and the RT, but not duration.

if key_resp.keys:
    print("resp made")
    #for key in keys:
    #    print(, key.rt, key.duration)
    continueRoutine = False

I’ve tried with ioHub and psychtoolbox as the input keyboard backend and neither provide duration. They both give the error AttributeError: 'Keyboard' object has no attribute 'duration'

I’ve also tried retrieving the key information, but that doesn’t work either.

if key_resp.keys:
    keys = key_resp.getKeys(['a','l'], waitRelease=True)
    for key in keys:
        print(, key.rt, key.duration)

Is there something else I can try? Here’s a small test experiment:
test_resp_duration.psyexp (15.3 KB)

Hello Joseph

does this help?

Best wishes Jens

1 Like

Did a little digging - this is interesting and unintuitive. This code should work if you put it in “Each frame”:

if key_resp.keys:

In short the builder is doing a little bit of deceptive magic and hiding the raw output of getKeys by putting it into the keyboard component object, but it skips the duration (which is something that should be looked at for a future version - I don’t have time to make the feature request now but I might later). However, it also creates a hidden variable that it uses to store the actual raw output, which is the one I’m referring to in this code block. That should let you access the duration information.

Thanks Jonathan, that worked! It also works in my local browser