# Iohub mouse wrong location (using Coder)

**URL:** <https://discourse.psychopy.org/t/iohub-mouse-wrong-location-using-coder/24085>\
**Category:** Coding\
**Created:** [July 16, 2021, 11:09pm UTC](https://discourse.psychopy.org/t/iohub-mouse-wrong-location-using-coder/24085 "2021-07-16T23:09:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iylarossi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/iylarossi/32/30306_2.png) [@iylarossi](https://discourse.psychopy.org/u/iylarossi)\
**Post date:** [July 16, 2021, 11:09pm UTC](https://discourse.psychopy.org/t/iohub-mouse-wrong-location-using-coder/24085/1 "2021-07-16T23:09:25Z")

</div>

Hi,

I am trying to set the computer’s mouse to a specific location using iohub (e.g., (0, -198)). The mouse is appearing at the location with the opposite y-value s.t. the mouse would appear at (0, 198) instead of (0, -198). However, the log data states that the mouse is at (0, -198) until it is moved, after which the log file recognizes the mouse is on the positive y-axis. I have searched my code, and it is not an issue with my code itself. I also have a black circle that is set to the same location as the mouse, and it does in fact appear at (0, -198) instead of (0, 198). Thus, I am pretty sure that the issue is not an error with how I am setting the position.

I have attached some code below that shows the issue. The code will print the position of the mouse so you can see that the mouse position will only register as (0, 198) after it has been moved, but the mouse does begin at (0, 198) instead of (0, -198). I have also attached images of the code and output, in case you cannot reproduce it on your computer.

Is this a known bug, or is there some kind of work-around that you can think of? It seems to be a systems error or Psychopy/iohub error, but I am not sure how to approach the issue. Note, I am using macOS Big Sur with an intel i7 processor. Any help would be greatly appreciated. Thank you!

~Iyla

```auto
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from psychopy.iohub import launchHubServer
from psychopy.iohub import devices
from psychopy import visual

io = launchHubServer()
mouse = io.devices.mouse
keyboard = io.devices.keyboard

win = visual.Window(
    size=(1440,900), fullscr=True, screen=0, 
    winType='pyglet', allowGUI=False, allowStencil=False,
    monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
    blendMode='avg', useFBO=True, 
    #useRetina=True,
    units='pix')

cursor = visual.Circle(win, radius=5, edges=32, units='pix', pos=(0, -198), fillColor='black', autoDraw=True, autoLog=True, name='cursor')

mouse.setPosition(cursor.pos)
while len(keyboard.getEvents())==0:
    if len(mouse.getEvents()) > 0:
        print('---------------------- \nmouse event occurred \n----------------------')
    cursor.draw()
    print(mouse.getPosition())
    win.flip()

win.close()
io.quit()

```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/b/db76443190404b8187f18bafe4ffaea65fb497a0.jpeg)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/6/0/608cab88a614762397c7d34b777cd5b5b59231fd.jpeg)

---

<div class="post-metadata">

**Author:** ![sol](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/sol/32/15018_2.png) [@sol](https://discourse.psychopy.org/u/sol)\
**Post date:** [July 22, 2021, 12:51pm UTC](https://discourse.psychopy.org/t/iohub-mouse-wrong-location-using-coder/24085/4 "2021-07-22T12:51:14Z")

</div>

Looking at this further on macOS, it seems that the issue maybe related to the code provided and recent update to iohub where `launchHubServer` now likes to be passed the psychopy Window being used. I’ve modified your example slightly, can you please try running it? This is running on PsychoPy 2021.2.0 on macOS.

```auto
from psychopy.iohub import launchHubServer
from psychopy import visual

win = visual.Window(
    size=(1440,900), fullscr=True, screen=0,
    winType='pyglet', allowGUI=False, allowStencil=False,
    monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
    blendMode='avg', useFBO=True,
    #useRetina=True,
    units='pix')

io = launchHubServer(window=win)
mouse = io.devices.mouse
keyboard = io.devices.keyboard

cursor = visual.Circle(win, radius=5, edges=32, units='pix', pos=(0, -198), fillColor='black', autoDraw=True, autoLog=True, name='cursor')

mouse.setPosition(cursor.pos)
while len(keyboard.getEvents())==0:
    cursor.draw()
    mpos = mouse.getPosition()
    cursor.pos = mpos
    win.flip()

win.close()
io.quit()

```

thanks again, sorry for the confusion.

---

<div class="post-metadata">

**Author:** ![iylarossi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/iylarossi/32/30306_2.png) [@iylarossi](https://discourse.psychopy.org/u/iylarossi)\
**Post date:** [July 22, 2021, 4:54pm UTC](https://discourse.psychopy.org/t/iohub-mouse-wrong-location-using-coder/24085/5 "2021-07-22T16:54:47Z")

</div>

Hi @sol,  
Thank you so much for your input. I am running 2021.1.3 on macOS, and I received this error when running your code:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/7/4/74618ed0aa83a69fb8eedc611b7245839c582322.jpeg)

---

<div class="post-metadata">

**Author:** ![sol](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/sol/32/15018_2.png) [@sol](https://discourse.psychopy.org/u/sol)\
**Post date:** [July 22, 2021, 8:31pm UTC](https://discourse.psychopy.org/t/iohub-mouse-wrong-location-using-coder/24085/6 "2021-07-22T20:31:23Z")

</div>

The code example requires 2021.2.0, are you able to upgrade? Thank you

---

<div class="post-metadata">

**Author:** ![sol](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/sol/32/15018_2.png) [@sol](https://discourse.psychopy.org/u/sol)\
**Post date:** [July 23, 2021, 1:43pm UTC](https://discourse.psychopy.org/t/iohub-mouse-wrong-location-using-coder/24085/7 "2021-07-23T13:43:17Z")

</div>

@iylarossi, I’ve been testing more on macOS using 2021.2.x and there does seem to be an issue with iohub `mouse.setPosition()`: the set system cursor y position is inverted around screen center. So `mouse.setPosition((0,0))` works, but `mouse.setPosition(0,-200)` actually sets the system mouse position to (0,200). This is likely the same issue on 2021.1.3. Here is 2021.2.x code that works around the issue:

```auto
from psychopy.iohub import launchHubServer
from psychopy import visual

win = visual.Window(
    size=(1440,900), fullscr=True, screen=0,
    winType='pyglet', allowGUI=False, allowStencil=False,
    monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
    blendMode='avg', useFBO=True,
    #useRetina=True,
    units='pix')

io = launchHubServer(window=win)
mouse = io.devices.mouse
keyboard = io.devices.keyboard

cursor = visual.Circle(win, radius=5, edges=32, units='pix', pos=(0, -198), fillColor='black', autoDraw=True, autoLog=True, name='cursor')

# Invert y value passed to mouse.setPosition to
# work around current iohub mouse macOS issue. 
mouse.setPosition((cursor.pos[0],-cursor.pos[1]))

while len(keyboard.getEvents())==0:
    if len(mouse.getEvents()) > 0:
        mpos = mouse.getPosition()
        cursor.pos = mpos
        print(mpos)
    cursor.draw()
    win.flip()

win.close()
io.quit()

```

if you are using version \< 2021.2.0, remove the `window` arg from `launchHubServer`:

```auto
io = launchHubServer()

```

I’ll work on a proper fix next week. Thanks again for reporting the issue.
