| Reference | Downloads | Github


I have a problem with the mouse. I am checking for clicks inside 3 boxes using myMouse.isPressedIn(). This works, but I am doing this inside an animation and when I click the click is taken more than once. This despite the call to event.clearEvents(). If I slow things down everything is fine, but that ruins the animation. Basically is there either a way to ‘downsampling’ the reading of the mouse, or to understand why event.clearEvents() does not work as expected?

I attached a fragment of the code with the loop, each box toggles an element in the animation. Thanks!

if myMouse.isPressedIn(box1):
            frame1on = not frame1on
elif myMouse.isPressedIn(box2):
            frame2on = not frame2on
elif myMouse.isPressedIn(box3):
            frame3on = not frame3on

The mouse isn’t like the keyboard, which sends discreet single clicks. It sends essentially the current state. isPressedIn() will be True on every frame that the mouse is held down for (it’s exceedingly hard to press and release within 16.6ms).
I think you’re wanting something to detect change in mouse state rather than whether it is currently down. The following works slightly differently to your code: checks if button is down, then checks whether it just went down and then checks where the mouse is.

# init (e.g. begin routine)
buttonWas = 'up'

# each frame
if myMouse.buttons[0]:
    if buttonWas=='up':
        if box1.contains(myMouse):
            frame1on = not frame1on
        elif box2.contains(myMouse):
            frame2on = not frame2on
        elif box3.contains(myMouse):
            frame3on = not frame3on
    buttonWas = 'down'
    buttonWas = 'up'