| Reference | Downloads | Github

How do I check whether the mouse cursor is in a stimulus?

OS Win10
PsychoPy version 2020.1.3
Standard Standalone? yes

What are you trying to achieve?:

Hi there, so I’m trying to build a visuomotor rotation experiment in Psychopy. I’m completely new to Psychopy and Python (have been using Matlab though). So far I have a starting circle, a mouse cursor (which is updated each frame) and a target circle. I want the target circle to appear after the mouse cursor has been in the starting circle for a random period between 500 and 800ms. Once the movement is initiated, the cursor should disappear and reappear when it crosses the distance to the target circle (this means it should reappear at the same radius as the target but it may be at a different location).

What did you try to make it work?:

In order to to have the target circle appear after a certain time, I added a code component and I’m checking “each Frame” whether the mouse is in the starting circle. Then I can add a a random delay after which the target appears and movement is initiated. This is how I’m doing it:

if baseline_mouse.getPos() in baseline_fixation.pos():
    baseline_target_circle.opacity = 1
    baseline_fixation.opacity = 0
    baseline_fixation.pos = baseline_mouse.getPos() - mouse_center

baseline_fixation is my starting circle.

What specifically went wrong when you tried that?:

So first of all, I’m not sure if this is the right way to approach it. Is it better to use the ‘condition’ option in the components? Second, the code gets stuck at the first line when checking if the mouse is in the target. I know this is a coding problem but I don’t seem to be able to find the right way to phrase this…

This is the error I get:

if baseline_mouse.getPos() in baseline_fixation.pos():
TypeError: ‘numpy.ndarray’ object is not callable

Include pasted full error message if possible. “That didn’t work” is not enough information.


if baseline_fixation.contains(baseline_mouse):

That works! Thank you :slight_smile:

Would you have any advice how I could get the cursor to reappear when it crossed the distance to the target circle? It seems that python has many built-in functions that make things relatively simple, I just don’t even know where to start looking yet (sorry, total newb here).

This post might help

1 Like

I will try that! Thanks a lot :slight_smile: