Delaying the end of a routine
Ending a routine on a key press or mouse click can be handled within the response component. If you want to change the display before ending the routine then there are two possibilities.
The first option is to create a second routine which is a copy of the original one which has a fixed duration, no response component and is customised based on the response from the previous routine.
The second option is to edit the response component so that it doesn’t end the routine and then set continueRoutine = False after a delay in a code component.
For example, if you want to hide visual components on the left or right based on a right or left key press:
Begin Routine
hideLeft = False
hideRight = False
endTrial = 9999 # Default routine duration
Each Frame
if t > endTrial:
continueRoutine = False
elif key_resp.keys and endTrial == 9999:
if 'left' in key_resp.keys:
hideRight = True
elif 'right' in key_resp.keys:
hideLeft = True
endTrial = t + 1 # Routine will end 1 second after the key press.
The visual components are then set to end on the condition hideLeft
, hideRight
or hideLeft or hideRight
.