SetPos() in visual.CustomMouse workaround?

Hello there,

I am relatively new to coding with Python/PsychoPy. I wrote a code that makes use of the visual.CustomMouse class because it has the ability to restrict the movement of the mouse to a certain area (in my case I need to restrict mosue movement to vertical movement so no change in X axis). The issue is however that visual.CustomMouse does not support the setPos() function (as stated on the psychopy website isteslf) and whenever I try I recieve the error:

“setPos() takes exactely 2 arguments (3 given)”

for mouse.setPos(0,-22). Considering this is a major drawback of this class I was wondering if there is a workaround for this (I could not find one so far).

Alternatively, is there a way to use the regular event.Mouse class (as it supports SetPos()) and restrict its movement some other way ?

I use psychopy libraries in Python 2.7 (Spyder3) on a Win7 (64bit) system. I use a ‘pygame’ window if that helps.

Thank you !

Hi,
you get the error because the input should be mouse.setPos([0, 22]) or `mouse.setPos((0, 22)). You should be able to achieve what you want by using event.Mouse.
I don’t know if got your problem correctly, but if you want to vary only the y just update the y input in setPos() and keep the x stable as you said.
I hope this helps.
Cheers

Thank you for your speedy reply.
If I use the setPos() function the way you describe, I get following error:

NotImplementedError: setPos is not available for custom mouse

So it seems the set pos is indeed not supported by the CustomMouse class.

Fortunately, I found a way to implement the restriction the mouse movement of a event.Mouse class as you said.

x,y=mouse.getPos()
mouse.setPos(0,y)

works like a charm

Thank you for your help !