Play the sound only if press the botton

Hello everybody,

I’ve been in Psychopy for a short time and I have a little problem.

I have a looping trial with two routines, one routine with pressing ‘m’ and ‘z’. In the other routine, I have two sounds. when pressing ‘z’ or ‘m’ it goes to the next routine where you can listen to one of the two sounds randomly. Then the trials are generated again with the loop.

The trials last 2.4 s. The button press routine is 2.4 and the sound routine is 0.5 s, which starts at 1.9 s trials. I want to make it so that only the sound is presented when the button is pressed.

The problem I have now is that if I don’t press the button at 1.9 the sound is still heard.

I have this code in the button routine

response = event.getKeys(keyList=[‘z’,‘m’])
if ‘z’ in response:
cue_voice1.play()
if ‘m’ in response:
cue_voice1.play()