Multiple keyboard inputs causes the next routine that utilizes that input to be skipped

I have designed a task meant for fMRI, the fMRI interface sends “s” inputs into psychopy every 1.6s (basically the equivalent of pressing “s” every 1.6s for over 5 minutes). This will occasionally cause the “s” key to be pressed in the next routine (hence skipping that routine) that utilizes that key response.

I have also managed to recreate this issue in just 4 routines. Follow the instructions on the Routine Skipping Issue.psyexp to recreate the issue I have faced. (The issue is inconsistent, pressing faster and for longer seems have a higher likelihood of triggering the skip.)

Routine Skipping Issue.psyexp (24.2 KB)

PsychoPy version: v2024.1.0
Windows 11 (occasionally on a Macbook as well)

Hi There,

Thanks for making a minimal demo for us to test - I am on a mac my end so cannot test - however I will ask someone else to test it who is on windows too.

In general though, if your scanner is sending the “s” key trigger i would suggest not using this as a response key in the actual experiment (if I have understood correctly that this is the problem). PsychoPy doesn’t differentiate between the scanner emulated keypress and actual keypresses, so in general it might be good to change your response key to a key other than “s” if possible.

Becca

I think I get why this is happening - because key_resp_2 is only looking for “d”, any other keypresses (such as “s” from your fMRI) aren’t cleared so are detected on the first call to getKeys where “s” is in the list of allowed keys (i.e. the first frame of Skipped_routine).

It’s a difficult one to handle because we don’t want to always be clearing all responses - otherwise e.g. listening to “Escape” to end the experiment would clear all responses each frame. Perhaps the best way to go is to say that if “Discard previous” is ticked, we start the Routine by clearing all responses on the Keyboard Component?

This will take a bit of discussion to come up with the best behaviour for all use cases, in the meantime you can avoid this by adding the following code to the Begin Routine tab of a Code Component in the equivalent of Skipped_routine in your actual experiment:

key_resp_3.getKeys(clear=True)

(this will get all key responses and clear them at the start of the Routine, meaning they won’t be detected later and the Routine won’t be skipped)

Thanks for the response! Prior to posting this, I’ve tested this solution to no avail. The issue with this is the inconsistencies that I’m facing where I’m not sure what triggers the key response to be saved for the next routine.

I’d think that the “s” are cleared, but there is another issue stemming from repeatedly pressing “s” that causes the clearing of the keys to not occur.