Freezing the experiment by pressing the 'enter' key

If this template helps then use it. If not then just delete and start from scratch.

OS WIN11
PsychoPy version 2022.2.3
What are you trying to achieve?: I would like for the entire length of the experiment, in case the subject presses the ‘enter’ key, the experiment will stop and a slide will appear in the style of ‘the experiment is paused, thank you’. Is there such a possibility?

I’m not interested in completely exiting the experiment screen like with the ‘escape’ key

Hello,

yes that is possible. Add “return” as a possible response key, add “feedback”-routine, insert a code-component at the Begin routine tab of your “feedback”-routine, check if “return” has been pressed, present your break-screen, otherwise skip your “feedback”-routine.

see example

Return.psyexp (14.4 KB)

Best wishes Jens

I wrote this code

But the experiment is stuck when it comes to this routine

Hello,

you need to check whether there was a response in your trial otherwise your experiment crashes with:

if 'return' in key_resp.keys:

TypeError: argument of type ‘NoneType’ is not iterable

So change your code to

if key_resp.keys:
    if 'return' in key_resp.keys:
        msg = "break"
else:
    continueRoutine = False

Initialize msg in the Begin Experiment tab with

msg = " oops"

I always initialize variables, especially feedback variables to check the if-else construction. Set $msg in the text-parameter of the feedback text-component to set every repeat

Best wishes Jens