Using the mouses position as a trigger

Hello,

I am trying to use the mouses psoition as a trigger to go to the next trial. So if they hover in a spot for lets say 2 seconds then it will go to the next trial. I want to remove the clicking aspect of it so its just works on time. If I can get it to a oint were it will go based on the cooridance than that will be fine too.

Hello,
I created an experiment demonstrating it for you.
When the routine starts, we create a timer which is 2 seconds long. We then save the position of the current mouse position.
Then, for each frame, we check if the current mouse position equals the mouse position we saved in the previous frame. If they are not equal, it means the mouse moved. In this case, we reset the timer and save the current mouse position again.
If the timer reaches zero, we continue to the next routine.
We repeat this test on each frame.

# Start Routine
timer = core.CountdownTimer(2)
mousePosition = mouse.getPos()

# Each Frame
text.text = timer.getTime() # Visualize the change

if (mousePosition != mouse.getPos()).any():
    timer.reset()
    mousePosition = mouse.getPos()

if timer.getTime() <= 0:
    continueRoutine = False

You can read more about timers and psychopy.core here.

You can download the example below:
mouse_movement_timer.psyexp (9.9 KB)

Oh that’s awesome. Thank you. I’ll read more about the timers

1 Like

Great, let me know if you need further help.