psychopy.org | Reference | Downloads | Github

Sound after a specific key response

So i am trying to design an experiment in which there needs to be a sound following a key response. For instance, if the user presses the “Y” key, sound A will play. If the user presses the “N” key then no sound will be played. I would greatly appreciate any insight as to how to make this happen?

If your keyboard component is set up to force the end of its routine, then in the next routine, which is set to play the sound, you would put code something like this in the “begin routine” tab of a code component:

if your_keyboard_component_name.keys == 'N':
    continueRoutine == False

i.e. the sound-playing routine won’t even start if the ‘N’ key was pressed.

Alternatively, whether the sound component is in the same routine or a separate one, you can set its start to be by “condition” rather than by a time value, and put in an expression like this:

your_keyboard_component_name.keys == 'Y'
1 Like