| Reference | Downloads | Github

PsychoPy experiment sets focus outside window when launching Eyetracker calibration

Hi, I’ve coded an experiment intended to be use with an Eyetracker machine.

The main structure of the code was generated using the Builder View, and then it was modified as needed using the Coder View (both in standalone version), so the default structure of how PsychoPy do things is mostly intact.
the code itself works just fine, but I’m seeing a weird behavior when launching the Eyetracker calibration.

The experiment starts as it should, in full-screen mode, and the user goes through the first blocks of the experiment with no issues. At the start of the main loop, a calibration is launched, which creates a brief CMD-like window to pop-up on the first screen, and at this point, the focus of both keyboard and mouse goes to that screen too, so if the user starts typing, he/she starts typing on the code, which is a serious risk as you may guess. So far the only solution we have to this, is to manually move the mouse to the second screen and click it, and then everything works fine. But I was tasked to search for a permanent and automatized solution.

To better understand this, the experimental setup is as follows:
The EyeTracker is connected to its host PC and its own screen (nothing wrong here). The display PC, which we use to launch PsychoPy, has 2 screens. The first one is used to launch the experiment, and the second one is used to display the experiment to the user.

I’m attaching the code, the conditions file and the library for EyeTracker functions (EDIT: i had to remove the last one, because I can’t attach more than 2 files as a new user…). The only thing missing are the images, because there are 65 of them, and looks like I can’t upload a .zip version containing all of them. Still, anyone testing this code can just replace the names of the conditions file and use anything he/she has.

For current testing purposes without the machine itself, the EyeLink-related lines are commented.

Your help would be much appreciated.

conditions.csv (16.9 KB) (128.5 KB)

Hi, I don’t know how the EyeLink package works in particular, but I have encountered the behavior you describe with ioHub, which fires up a new process on initialization, causing the main window to lose focus. Have you considered moving the entire EyeLink initialization above the code section where you create the window? Probably just below the import statements or so would be best… Does that help?

Edit: Oh, I just realized EyeLink init requires an existing Window object. Mh. :frowning:

Hopefully @richard’s win.winHandle.activate() should work for you; let us know if that doesn’t.

One tricky bit that I came across in a very similar scenario was using opencv to show the eye window: creating the opencv window was stealing focus from psychopy (and thus preventing keypresses, etc.). To deal with this, you can either grab and draw one opencv frame outside the loop, or even better initialize the window with cv2.namedWindow, and then use win.winHandle.activate() to return focus to psychopy.

Let us know if you’re still having trouble,