| Reference | Downloads | Github

Freeze mouse, unfreeze mouse, continue routine




I am using Psychopy to have people rate pictures. I want to freeze the mouse when somebody presses the left mouse button and unfreeze it when somebody presses the right mouse button (in my script it is ‘space’). If the mouse is frozen, a second mouse click should ideally continue the routine. I am pretty new to psychopy, and just can’t get this to work. I have an invisible event.Mouse (named mouse) and a visible custom mouse (named mouse_Like) in my script. Is there something like a pause function to stop updating the mouse location? I pasted the important parts below.

    leftLimit=-.29, topLimit=.85, rightLimit=-.29, bottomLimit=-.85,
    showLimitBox=False, clickOnUp=False)

mouse= event.Mouse(visible=False, win=win)
x, y = mouse.getPos()

----------start of routine-----------

 while continueRoutine:
        mouse1, mouse2, mouse3 = mouse.getPressed()
    # *mouse* updates
        if t >= 0.0 and mouse.status == NOT_STARTED:
            # keep track of start time/frame for later
            mouse.tStart = t
            mouse.frameNStart = frameN  # exact frame index
            mouse.status = STARTED
            prevButtonState = mouse.getPressed()  # if button is down already this ISN'T a new click
        if mouse.status == STARTED:  # only update if started and not stopped!
            buttons = mouse.getPressed()
            if buttons != prevButtonState:  # button state changed?
                prevButtonState = buttons
                if mouse3:  # right click
                    event.waitKeys(keyList='space') # freeze mouse and unfreeze with space
                    if mouse3: #this makes it go on automatically after unfreezing

Thanks!! Would be glad for any help!