Psychopy - Remove Escape key from global keys using Python code - not builder

Trying to keep things simple and short. We have created a fairly complicated series of questionnaires/face recognition task using Psychopy code - not the builder. We will be running this on a number of participants within a clinical setting, with data produced by the participants being extremeley confidential and sensitive, thus we would like to make sure no participant or anyone without permission, to close the experiment/python and start exploring the contents of the machine.

Right now, psychopy can be fairly easily exited by just pressing the ‘Esc’ key. From reading around, this can be changed using the psychopy builder- however, for serveral reasons, we have not used the builder and am wondering whether there is a code/script alternative. Or if anyone has any good solution to make sure someone cannot quit psychopy unless, say, a very specific key sequence is entered - although we already have this for the end of the experiment.

The main issue seems to be, that when psychopy is not expecting or waiting for a keyboard event - the ‘Esc’ key can be pressed to quit.

Another caveat is for certain packages we have to run this in an older version of psychopy 1.82.01, python 2.7

Hope this information is at least enough to get some responses!

Thanks guys!

This behaviour has to be explicitly coded. e.g. Builder-generated files have something like this:

# check for quit (typically the Esc key)
 if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
    core.quit()

So if your experiment responds to the escape key, it is only because you have told it to. Simply stop doing that. i.e. The operating system doesn’t pay attention to whether a person pushes the escape key, programs have to give it some meaning within the context of their own needs.

Having said that, I don’t think we can necessarily override combinations the operating system does give special meaning and priority to (e.g. control+alt+delete on Windows or command+option+escape on a Mac): they will still allow a user to force quit your experiment and get access to the system.

The main issue seems to be, that when psychopy is not expecting or waiting for a keyboard event - the ‘Esc’ key can be pressed to quit.

In summary, this is not the case: PsychoPy ignores the keyboard completely and at all times, unless explicitly told to do otherwise (as in the code snippet above).

Thanks for the reply.

I feel a slight fool - as it turned out, sneaking in our code was a snippet waiting for the ‘Escape’ key :stuck_out_tongue:

DARNNNNNNNNN

I think that problem is somewhat resolved

Now need to figure out how to stop a crash of psychopy/python or work around allowing someone to access files on the computer!

Thanks!