I’m trying to make an experiment where a cursor moves when the mouse moves. In addition, there’s some jitter added to the movement, but only when the mouse is moved. I can’t get this to work. Here’s what I’ve tried, and a few bumps along the way:
Simple version: just mouse movement
This works, but changing the sensitivity (
/ 2)of the mouse causes the cursor to stop moving beyond 25% from the center-point of the screen. It’s as if it’s captured in a box.
import numpy as np from psychopy import visual, event win = visual.Window(fullscr=True) cursor = visual.Circle(win, radius=0.02) mouse = event.Mouse(visible=False) # Loop until mouse press while not mouse.getPressed(): # Do something if mouse moved move = mouse.getRel() if np.any(move): cursor.pos += move / 2 # change sensitivity #cursor.pos += np.random.randn(2)*0.01 # random jitter #mouse.setPos(cursor.pos) # move outside "box" #mouse.lastPos = cursor.pos # do not count setPos as movement cursor.draw() win.flip()
Moving the cursor beyond the “box”
Try outcommenting the line
to make the system mouse “follow” the cursor object, so that it should be able to move to the physical screen edge. Now I see a weird behavior where the mouse is “dragged” towards the center, so
mouse.getRel() captures this position setting as a movement. To fix that, outcomment
#mouse.lastPos = cursor.pos
It works! Yay!
Movement jitter on physical mouse movement
Outcomment the last line to add jitter to the cursor position, and thereby also to the
cursor.pos += np.random.randn(2)*0.01
The problem is that it jitters even though the mouse is still. And sure enough,
mouse.getRel() returns non-zero movement as does replacing it with
mouse.getPos() - cursor.pos. I’ve also tried replacing
mouse.mouseMoved() but no dice.
Is there a way to get the desired behavior?