| Reference | Downloads | Github

Custom Mouse "locks" in the center when using pixel units


I have the feeling this might be a very silly issue but here we go:
I’m using a CustomMouse in my experiment, for which I set up a TextStim as a pointer. The custom mouse works fine and I can move it around the screen as long as the TextStim units are set as ‘norm’. However if I try to specify the units as pixels, the cursor appears to be locked in a very tiny area close to the center of the screen. In theory this should not be related to the virtual box limits of the CustomMouse, as I specifically set them to be non existant. My default units in PsychoPy’s preferences are set as ‘norm’.
Example code:

crosshair = visual.CustomMouse(win)
moving_pointer = visual.TextStim(win, text=‘x’, height=0.1, units=‘norm’)
locked_pointer = visual.TextStim(win, text=‘x’, height=30, units=‘pix’)
crosshair.pointer = locked_pointer

What am I missing here?

The doc for customMouse notes that it currently only works with “norm” units:

So, my guess is you’re doing everything right, it’s just not currently built to work with pixel units. However, converting back and forth is just a bit of math. If Z is the target height in pixels and H is the height of your window, then the computation is simply:

Norm = Z/(H/2)

(H/2 because norm units go from -1 to +1, so the total height of your window is “2”)

1 Like

Hello Jonathan, thanks for your reply! I can’t believe I missed that on the CustomMouse doc after having visited that page a dozen times these days. Thanks a lot for your tip too, that’s very useful!
In the mean time I had found another workaround: as my main issue involved getting the position of the cursor in pixel units, I saw in the TextStim doc that there’s a specific class called posPix, which returns the position in pixels. Given that the pointer for my custom mouse was a visual.TextStim and going back to my original example, instead of doing


and getting that info in norm units, it is possible to get the position of the custom pointer in pixels simply with:


Maybe this will help someone else in the future.