# SetPos() in visual.CustomMouse workaround?

**URL:** <https://discourse.psychopy.org/t/setpos-in-visual-custommouse-workaround/1300>\
**Category:** Coding\
**Tags:** mouse, cursor\
**Created:** [October 17, 2016, 8:52am UTC](https://discourse.psychopy.org/t/setpos-in-visual-custommouse-workaround/1300 "2016-10-17T08:52:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fischer1275](https://avatars.discourse-cdn.com/v4/letter/f/838e76/32.png) [@fischer1275](https://discourse.psychopy.org/u/fischer1275)\
**Post date:** [October 17, 2016, 8:52am UTC](https://discourse.psychopy.org/t/setpos-in-visual-custommouse-workaround/1300/1 "2016-10-17T08:52:27Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![porcu.emanuele](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/porcu.emanuele/32/735_2.png) [@porcu.emanuele](https://discourse.psychopy.org/u/porcu.emanuele)\
**Post date:** [October 17, 2016, 11:11am UTC](https://discourse.psychopy.org/t/setpos-in-visual-custommouse-workaround/1300/2 "2016-10-17T11:11:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fischer1275](https://avatars.discourse-cdn.com/v4/letter/f/838e76/32.png) [@fischer1275](https://discourse.psychopy.org/u/fischer1275)\
**Post date:** [October 17, 2016, 12:46pm UTC](https://discourse.psychopy.org/t/setpos-in-visual-custommouse-workaround/1300/3 "2016-10-17T12:46:45Z")

</div>

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 !
