Mouse click getPos() function not updating with each new click

I am using mouse clicks as part of a visual world paradigm (VWP) experiment, but running into issues with the x and y coordinate information of clicks on each trial.

I will put the most relevant code below as I describe what I have attempted and what has/hasn’t worked. Note though that this is an experiment meant to interface with EyeLink, and will not work without pylink and connection to an eye-tracking camera. My full experiment and dependent files can be found on Google Drive: Shared_experiment_for_forums - Google Drive

Each trial, I have two mouse click actions called center_mouse_click and VWP_mouse_click. The task is design so that the VWP appears with a play button in the middle. The subject has to look to center and click the play button, which immediately plays an audio file and the play image disappears. Then, a second click anywhere on the screen (though presumably on one of the VWP images) ends the trial. The entire experiment works, meaning that click actions do progress the program code as intended.

What does not work: The information about the x and y coordinate of each click does not update from one trial to the next. For example, in the code chunk below I use the getPos() function in the line x, y = center_mouse_click.getPos(). Based on the documentation of that function, I would think that I should get the x and y value of the most recent click… but that isn’t the case. I have some print statements to check what is happening, and essentially the very first click of the experiment sets the x and y value and does not change each new trial.


# *center_mouse_click* updates: check for click on play button
        if center_mouse_click.status == NOT_STARTED and t >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            center_mouse_click.frameNStart = frameN  # exact frame index
            center_mouse_click.tStart = t  # local t and not account for scr refresh
            center_mouse_click.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(center_mouse_click, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.addData('center_mouse_click.started', t)
            center_mouse_click.status = STARTED
            center_mouse_click.mouseClock.reset()
            prevButtonState = center_mouse_click.getPressed()  # if button is down already this ISN'T a new click
        if center_mouse_click.status == STARTED:  # only update if started and not finished!
            buttons = center_mouse_click.getPressed()
            if buttons != prevButtonState:  # button state changed?
                prevButtonState = buttons
                if sum(buttons) > 0:  # state changed to a new click
                    # check if the mouse was inside our 'clickable' objects
                    gotValidClick = False
                    
                    # Determine if there was a click on center play button
                    x, y = center_mouse_click.getPos()
                    print("center click x =", str(x))       # use these print statements for troubleshooting
                    print("center click y =", str(y))
                    
                    if x < 0.20 and x > -0.20:       # note: these values restrict to click on center button
                        if y < 0.20 and y > -0.20:
                            gotValidClick = True
                    
                    center_mouse_click.x.append(x)
                    center_mouse_click.y.append(y)
                    buttons = center_mouse_click.getPressed()
                    center_mouse_click.leftButton.append(buttons[0])
                    center_mouse_click.midButton.append(buttons[1])
                    center_mouse_click.rightButton.append(buttons[2])
                    center_mouse_click.time.append(center_mouse_click.mouseClock.getTime())
                    if gotValidClick:
                        continueRoutine = False  # abort routine on response

I thought a logical solution to this would be resetting the mouse actions each trial iteration (seems logical, no?) but that also doesn’t work. I have attempted adding the chunk below to the start of each trial loop, and it did nothing.


    center_mouse_click.clickReset()
    VWP_mouse_click.clickReset()

Any ideas on why the getPos() function isn’t behaving as I expected it to, or why the clickReset() functions aren’t helping with the issue?
Any ideas on other ways to solve this type of issue?

Thank you to any help or advice you can provide!!!

What version of PsychoPy and what type of computer are you using?

I thought this sounded somewhat familiar and indeed there are two previous posts that might be related to this but neither has a directly applicable solution:

My general suspicion is that it’s a resurgence of the issue in the first post having to do with the pyglet window, but I’m not sure. There’s no obvious reason for it otherwise. @jon might know more.

Hi Jonathan – I am using PsychoPy 2022.2.5.

I will look into these posts to see if they can help resolve the issue. Thanks for linking to them!