1

I would need to allow the mouse cursor to cross the upper edge of the screen. And ideally to activate/deactivate this option with some python code. I couldn't find any clue about how to do that. Any idea?

The reason why:

I am coding a psychology experiment in python (psychopy). I must constantly deviate the mouse cursor downward when it moves in a certain area of the screen. I was doing that by changing the cursor position accordingly to the desired deviation with some pymouse/psychopy functions.

However, when I ran this experiment on a new computer (I must), it froze systematically. So I tried a new method: displaying a shape (a circle) in psychopy which moves according to the real cursor+deviation while keeping the real cursor unchanged (just hiding it). However, as the real cursor isn't allowed to cross the upper edge of the screen, it is blocked at a certain height, which impedes the movements of the secondary circle cursor I created. In other words, this secondary cursor can't move as high as it should, because the real cursor cannot go higher than the upper edge of the screen.

If you have any tips about the fuller issue, please let me know!

thanks!

Mohsen mokhtari
  • 2,841
  • 1
  • 30
  • 39
G.Gab
  • 11
  • 1

1 Answers1

0

As you've found, the approach of drawing your own stimulus controlled by mouse position, rather than manipulating the operating system's mouse pointer, is probably more robust and flexible. So definitely continue with that approach.

However, PsychoPy relies on the operating system to report the mouse coordinates, and those are inherently bounded by the limits of the screen. So you would need to come up with your own workarounds to allow off-screen pointer motion.

  • You could try looking at what happens by using multiple monitors, i.e. with a second monitor set up (not necessarily visible to the participant, and not necessarily even in the same room) such that it is configured virtually to be above the primary monitor, with the mouse able to transit to it. But I have no idea how PsychoPy would deal with the mouse coordinates if the pointer transitions to a second screen.
  • Alternatively, when the mouse y coordinate hits zero, you could calculate a predicted trajectory for the mouse pointer based on its previous motion. PsychoPy will quite happily allow you to set a position for a stimulus that is partially (or completely) outside the bounds of the window, so this would allow your secondary cursor image to smoothly transition off-screen.

    How to do this sort of prediction? You could do some sort of crude linear interpolation, based on keeping a lagged record of the mouse position as few samples back in time and just keep following along a straight line between that and the last within-window position. For something that could capture curved trajectories and velocity, I'm not sure if this is relevant, but try googling for kalman predictive filter mouse tracking python

Mohsen mokhtari
  • 2,841
  • 1
  • 30
  • 39
Michael MacAskill
  • 2,411
  • 1
  • 16
  • 28
  • Blender automatically warps the mouse pointer to the opposite side of the viewport when it's being used in a relative positioning mode. It does fail though if there's another window on top of Blender. – John Dvorak Feb 11 '20 at 22:12
  • Thank you so much! For the second option, it may add noise and be quite costly in terms of coding and all. And I would like to get accurate trajectory measures, like changes in direction that are not really predictable. The first option sounds the best so far. Ideally I would need to set a virtual monitor positioned above the real screen. Any suggestion about how to do that? – G.Gab Feb 12 '20 at 10:23
  • I'm not much of Windows user, but this is something to set up and configure in your Windows control panel's monitor settings. There will be settings there to extend the desktop from one screen to another, and arrange spatially how the the monitors relate to each other, in terms of how the mouse would transition from one to the other. e.g. https://www.windowscentral.com/how-connect-and-set-multiple-monitors-windows-10 Having said that, I have no idea how PsychoPy would work with reporting mouse position once the pointer leaves the primary screen - it might just stick at the boundary value. – Michael MacAskill Feb 12 '20 at 23:00