End trial if no response detected

OS: Big Sur Version 11.2.2
PsychoPy: 2020.2.10

Hi, I’m new to PsychoPy, so apologies in advance if there’s already a simple solution for this. I am building a task where a stimulus appears for 5 seconds on random coordinates of the screen, and participants are asked to click on the stimulus before it disappears. If they fail to respond within the time window, the trial ends and the next stimulus appears. By setting the image duration to 5 seconds, the stimulus is gone after 5 seconds. However, as of now, the trial only ends once they respond, even if the stimulus is already gone. Is there a way to code this in a way such that if they respond, next trial begins right away, and if not, next trial automatically begins after 5 seconds?

Set the mouse component to also have a duration of 5 seconds


Should’ve done some more digging before I posted this! Found the solutions here: Customize Force End Routine - #4 by Oli

Used Michael’s code in case anyone else finds this helpful.