How to prevent keypress during stimuli

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): MacOS 10.14.1
PsychoPy version (e.g. 1.84.x): 1.85.4
Standard Standalone? (y/n) If not then what?: yes
**What are you trying to achieve?:
I’m trying to measure how fast participants press yes or no after audio stimuli ends, but the experiment accepts keypress during stimuli (audio)

**What did you try to make it work?:
I’ve been searching the forum here but I’m not sure what I can do at the moment.

**What specifically went wrong when you tried that?:
Nothing is wrong if participants wait until the end of the stimuli and then press keys, but I’m afraid some participants may press keys before the end of the stimuli and I’d like to prevent that.
Is there any way I can prevent keypress before the end of the stimuli?

1 Like

Hi,
you could set the Start of your keypress component to condition and enter the following code there:

$your_sound_component.status==FINISHED

Of course, your_sound_component needs to be replaced by the actual name of your sound component. That way, key responses will only be recorded when the sound component has ended.

1 Like

Hello,

  1. One simple solution can be: You can try adding core.wait(sec) right after your code of your_sound_component.play() in which sec is the number of duration of your sound play. It is basically telling the system to wait sec amount of seconds after the sound is being played.

  2. It can also be possible that your sound.play() is stated before event.getKeys() or waitKeys(). If event_getKeys is before sound.play(), then you want to move it so that event.getKeys is after sound.play().

Hope this helps.

@seedee is using Builder, so @TorgeMS’s approach will be the valid one here. @Jin_Jeon’s suggestion is fine but would only work in a custom-written script rather than a Builder-generated one.

Thank you very much for the replies!