Iohub mouse wrong location (using Coder)

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

#!/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()


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.

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.

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:

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

@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:

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:

io = launchHubServer()

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