I’m trying to track the position of the mouse cursor on the screen whilst drawing a line. I want to store the values of the position of the mouse to then later play back the drawing of the line with no input from the mouse itself.
I have two problems:
I set the mouse to zero and then get the position of the mouse, which does not return [0,0]. Instead it returns [-960,-450], the bottom left of the screen. This means it draws a line to the bottom left on the first few frames
I move the mouse to draw a line and record the position (all good here). I then set the mouse position to zero again and the cursor on the screen moves to [0,0]. Immediately after, I get the position of the mouse. This time, it just returns the last position of the mouse before I set it to zero.
Here’s the code:
import numpy as np from psychopy import visual, core, event winSize=(1152,870) # ** draw a line with the mouse and press space when done. Cursor will move back to fixation point. Will then replay your line-drawing** win = visual.Window(size=winSize, monitor='testMonitor', units='pix',bitsMode=None, allowGUI=False, winType='pyglet', fullscr=True) mouse = event.Mouse(visible = True) respLine = visual.Line(win, start=(0,0), end=(0,0)) respLine.end = (0,0) Fixation = visual.GratingStim(win,units='pix',sf=0,mask='circle',size=10) recordedMousePos = np.zeros((2,300)) mouse.setPos([0,0]) for nFrames in range(300): Fixation.draw() respLine.end = mouse.getPos() # should start at [0,0] on first frame but starts at bottom left respLine.draw() win.flip() for key in event.getKeys(): if key in ['escape','q']: core.quit() elif key in ['space']: mouse.setPos([0,0]) print 'setToZero',mouse.getPos() # should be [0,0] but it is not recordedMousePos[:,nFrames] = mouse.getPos() # print 'recordedPos',recordedMousePos[:,nFrames] #uncomment to see recorded pos of mouse on every frame # play the line drawing back ** should show cursor moving back to centre following space, but doesn't. mouse.setPos([0,0]) for nFrames in range(300): mouse.setPos(recordedMousePos[:,nFrames]) Fixation.color = 'blue' Fixation.draw() respLine.end = recordedMousePos[:,nFrames] respLine.draw() win.flip() for key in event.getKeys(): if key in ['escape','q']: core.quit()
Any help would be greatly appreciated!