| Reference | Downloads | Github

Is there a .isMovedInto function comparable to .isPressedIn

the .isPressedIn function is awesome! However, in my case the function should be called when the mouse is moved into an object - without clicking. Is there an equivalent .isMovedInto function or could the .isPressedIn function be hacked to respond to the mouse position without having to click?
Thanks for any suggestions,

Hi - there is nothing built in, but you can make it yourself using a code component in Builder.

in the Every Frame tab add the following:

mPos = mouse.getPos() #mouse is the name of your mouse component
if polygon.contains(mPos): #replace polygon with the name of your object
    continueRoutine = False #this just ends the routine but could be anything else you like

best wishes

1 Like

Thanks for the fast response. This sounded very good. However, it seems to detect LEAVING the area and not entering!? Any idea why that might happen - is it intended?
Here is the code (in builder, every frame).

mPos = mouse.getPos()
#if mouse.isPressedIn(target):   #previous code, worked on click
if target.contains(mPos):
    some code

“target” is a visual.Circle defined at start (with some changing X,Y values throughout the trial):

target = visual.Circle(win, size=(.15,.23),


I’m not able to replicate this with static positions - it might be something to do with wherever x and y are set from

Yes, you are right. The .contains() function works as expected.

I figured out what the problem was in the original code. It was a misunderstanding on my part. Of course, the function is not only called once upon entering the area, it is called repeatedly when in the area. In my code, I assessed the current time and this was updated all the time and the delayed response I intended never started (it was always “now”+0.5 sec). Only upon leaving the area, the function was not called anymore, the updating of the current time stopped and the delay could pass.
The same actually happend with the isPressedIn function; it was called repeately as long as you pressed but I didn’t notice it then because I just clicked and never kept holding it.
Thanks for the help,