Response Durations when Response Ends Trial

OS (e.g. Win10): Win 11
PsychoPy version (e.g. 2024.2.4 Py 3.8): 2025.1.1
Standard Standalone Installation? (y/n) If not then what?: Y
Do you want it to also run online? (y/n) No, locally only
**What are you trying to achieve?
**
I’m developing a Simon task and I need to include the response key press durations- I noticed that the resulting data file populated the responsekeys.duration column with “None.”

I realized that the issue is that I selected to force the end of the routine after responding and that results in the “none” in the duration column. I’m looking for some advice on how to get around this, since I need to end the trials after responding or up to 500ms after stimulus presentation, but I also need the key press duration.

Basic timeline of the experiment:

Stimulus presentation (CircleStim) 0-200ms > response (Responsekeys) until response or up to 500ms > RSI (generated by RSIcode) between 750-1100ms

RSIcode selects the position of the stimulus, generates an RSI value, and keeps track of the score. trialTriggers (disabled) sends EEG triggers to the data collection software which is working.

What did you try to make it work?:
I tried adding the following print statement in the ‘every frame’ tab of a code component:

print(_Responsekeys_allKeys)

which only worked when I unchecked the keyboard component to not force the end of the routine. It produced the following:

[<KeyPress from None: t=32.2623437000002, value=2, duration=None>]

Link to the most relevant existing thread you have found:

What specifically went wrong when you tried that?:

It did not produce a response until I selected not to force the end of the routine for the response, and even when I did get some information, I still had duration = None.

Any help or advice would be appreciated! Thank you for your time :grinning_face_with_smiling_eyes:

How about having two keyboard components: one that detects a press but doesn’t end the trial, and one that detects a key release and ends the trial?

2 Likes

Hello @R_Roy

Another option is to uncheck the Force end of Routine and set store: last key (is the default). Then add the following code to a code-component in the Each frame tab.

keys = kb.getKeys(['space'], waitRelease=True, clear=True)
if keys:
    press_duration = keys[0].duration
    thisExp.addData('press_duration', press_duration)
    continueRoutine = False

Change kbto the name of your keyboard-component (default is key_resp). I think you used Responsekeys. Specify the keys you need in keys = kb.getKeys(['space'], waitRelease=True, clear=True).

Best wishes Jens

2 Likes

This was a very elegant solution to the issue- thank you very much!