psychopy.org | Reference | Downloads | Github

Mouse equivalent of event.waitKeys()

Is it possible to have a task wait for the mouse to move (similar to event.waitKey)? I’ve had a look in the API and it doesn’t seem like there’s a function for this, but I can quite figure out how to implement this in the coder if controlling stimuli via frames (a way to stop the count of frames, or to pause frame counts until the mouse has been moved?)

any help would be massively appreciated!

@srchekroud, you could so something like this, where you create a condition in which you do not draw your stimuli until the mouse has moved:

from psychopy import locale_setup, visual, core, clock, event
import numpy as np

# Create win, stim and mouse
win = visual.Window()
text = visual.TextStim(win=win, name='text', text='default text');
mouse = event.Mouse(win=win)

# Create some handy timers
trialClock = core.Clock()
t = 0
trialClock.reset()  # clock
frameN = 120 # n frames to iterate

# Set mouse position for conditional start period
mouse.setPos((0,0))

#Begin loop
while True:
    if not np.any([mouse.getPos(),(0,0)]): # if mouse position is (0,0)
        text.setText("Are you ready?")
        text.draw()
        win.flip()
    if np.any([mouse.getPos(),(0,0)]): # if mouse position is not (0,0)
        for frames in range(frameN):
            t = trialClock.getTime()
            text.setText(round(t,2))
            text.draw()
            win.flip()
            if mouse.getPressed()[0] == 1: # quit if left mouse button clicked
                text.setText("You clicked a button")
                text.draw()
                win.flip()
                core.wait(1)
                core.quit()