Hold button until a signal appears

OS: Win 10
PsychoPy version: PsychoPy3 2020.2.5

Hi, I’d like to ask participants to hold a ‘ready’ button (i.e. hold the left mouse button down, no release) for a given time length until a signal cue (i.e. a polygon) appears, then they will need to release the ready button and to click on the polygon. The holding time is determined by a list and randomly selected for each trial. I’d like the timing starts from participants pressing down the mouse button and count for, say 2s, then show the polygon. If they released the button in the meanwhile, the timing restarts when mouse button down again.

How to use a code component in the Builder to time the duration of mouse-button-down? Or how to detect mouse-button-released after the initial press-down?

Hi There,

This demo should do what you need :slight_smile: download these files to the same folder and run the psyexp file.

mousHoldDemo.psyexp (22.6 KB) conditions.xlsx (8.5 KB)

Essentially we use a loop to ask participants to click and hold again if they lift their finger before lift time, we can use the conditions file to set the target time on each iteration.

Hope this helps,

Hi Becca,

Thank you so much! This demo does exactly what I wanted to achieve! I’ll try to integrate it into the task.

I’m new to PsychoPy and try to understand how the demo (and the builder) works. Most are clear to me, but there are several things I’m not entirely sure. I’m attaching two screenshots here and hoping you don’t mind letting me know if I understood this correctly or not. Much appreciated!


Hi Sean,

Fantastic. Your understanding of the trials and loops is totally correct.

For the mouse options:

End Routine = valid click means that when the participant clicks one of the component listed under ‘Clickable stimuli’ the routine ‘hold’ will end and progress to the ‘hitTarget’ routine.

Save mouse state = on click means both the coordinates and the RT (since the start of the mouse onset based on the ‘relative to option’) will be save in your output file under the column headers holdMouse_1.x, holdMouse_1.y and holdMouse_1.time

Hope this helps :slight_smile:


PS. please could you mark the corresponding answer as the ‘solution’ (the little tick box) for future users to see the accepted answer to this question :slight_smile:

Awesome! Many thanks, Becca! This is very helpful!