| Reference | Downloads | Github

Acknowledging mouse click without ending routine

OS (e.g. Win10): Windows 10
PsychoPy version (e.g. 1.84.x): 1.84.1
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:
I’m trying to make an image of a check mark appear whenever the participant clicks on either the left or right mouse button, without having the “End Routine on press” box checked.

What did you try to make it work?:
I added a Code Component in which I typed under the “Begin Routine” tab:

if mouse_1.getPressed():

What specifically went wrong when you tried that?:
This works exactly the way I want to, but only when I have the “End Routine on press” option enabled. The check mark shows up whenever I click the left or right mouse button after the stimulus disappears, after which Psychopy immediately starts the next trial. For my experiment, however, I want to give participants time to prepare for the next trial. This is why I gave the participants 5 seconds to respond. The problem with this is that participants might click multiple times if they think their click was not registered properly, which would influence the data output of the experiment, hence the idea of adding the check mark to acknowledge their response.

The rest of the routine and the data output work as intended. I was wondering if there was an easy solution to giving visual feedback in response to a mouse click without ending the routine.

Many thanks in advance!


1 Like

Could you post a screenshot of the settings for your ImageStim and show us more of the code in your code component (properly formatted: put three backticks (```) on the line above and the line below)? First guess would be to tinker with the dropdown next to the Image setting (constant vs. set every repeat vs. set every frame, etc.)

Hello Daniel,

This is the screenshot for the stimulus:

This is what the routine “PB1” looks like, along with the loop I used:

This is the code that I input in the code component underneath the “Begin Routine” tab

if mouse_1.getPressed():


After a closer look I think I better understand what you’re trying to do. So you just want to have the PB1 routine end when the mouse is clicked (doesn’t matter where they click)?

If that’s the case I don’t think you need a code component at all. On the mouse component in PB1, check “End routine”, and then when the mouse is clicked that routine will end.

Now I’m noticing you said you don’t want to check “End routine”, why might that be?

But for whatever reason you may have, your code should be in the “Every frame” of the code component. If it’s in “Begin routine”, it will run once, before your stimuli are being shown. You want it to constantly check if the mouse has been clicked, so that needs to repeat every frame. To stop the routine, you would also add continueRoutine = False .

if mouse_1.getPressed():
    continueRoutine = False