Participant key press writing into Coder script

When running a script from Coder, I have been encountering an issue where the participant’s keypresses are writing directly into the script itself, which depending on where the cursor is placed can derail the experiment as it is running (see screenshot below).

This issue most frequently occurs with an experiment that plays a video each trial, and so I have created a minimally reproducible example ( and video.mp4, attached below). The example script, as well as the real script I need to run, was created in Builder but run from Coder (I needed to implement timing fixes in my actual experiment which is why it must be run from Coder).

One thing I have noticed is that despite the inclusion of code that should remove the mouse from the screen on every repeat (and the Show Mouse box unchecked in Builder), the cursor reappears when the video plays. If I click to a space outside where the PsychoPy Coder window should be (for example, the top-right corner of the screen) when the cursor reappears, I can prevent the keypresses from writing into the script. But this is clearly not a reliable fix.

I have also realized that although the keyboard component in my example script only allows a 1 to be recorded, any key I press will be written into the script (see screenshot).

For reference, I am using PsychoPy v2021.2.3 on a Dell Precision 5560 laptop.

Any help would be greatly appreciated! (13.7 KB)