Is it possible to access participant key release with coding?

Hello PsychoPy community !

I’m trying to access participant key release but I can’t do it :weary:
In a routine I would like to have a sound that start when participant press a specific key (let’s say spacebar) and end when this participant release the key. The problem is that I don’t understand how to use the keyboard events (like getKeys or keyPress) in that purpose. And I guess this kind of things can’t be done with the builder.
Do someone have an idea on how to do that ?

Thanks in advance !

The tricky part of this is detecting a key release, detecting key presses is easy! Would it still work with your paradigm to have them press once to start the sound and again to stop?

Either way you will need to set the Start parameter of your Sound component to be a “condition” rather than duration, and have that condition be:
$ KEYBOARD .getKeys(waitRelease=False, clear=True)
(with KEYBOARD being the name of your keyboard component)
and if you would like an additional keypress to also end the sound, you could set Stop to be the same value.

Hi TParsons,

Thanks for your answer.
Yes, detecting a key release is not so simple :sweat_smile: I think it should work if participants press once to start and again to stop the sound even if it would have been better if they just have to press the key once.
Anyway, your solution works perfectly so thank you for that.

1 Like