mouse.getPressed behavior

Hi,

I would like to detect one mouse press and then do some stuff, however mouse.getPressed (in Each Frame) returns something like that:

Buttons: [0, 0, 0]
Buttons: [0, 0, 0]
Buttons: [0, 0, 0]
Buttons: [1, 0, 0]
element added, new seq = ['s3', 's12']
Buttons: [1, 0, 0]
Buttons: [1, 0, 0]
Buttons: [1, 0, 0]
Buttons: [1, 0, 0]
Buttons: [1, 0, 0]
Buttons: [0, 0, 0]
Buttons: [0, 0, 0]

The goal is to remove the 1es that comes after element added, new seq = ['s3', 's12'] How to achieve that?

The button is still pressed so you need to have a flag.

e.g.

if buttonPressed = False and mouse.getPressed[0] == 1:
     do stuff
     buttonPressed = True
elif buttonPressed = True and mouse.getPressed[0] == 0:
     buttonPressed = False

Thanks for the answer, however it won’t work in my case - specifically, when I want to do stuff twice, three times, etc., WITHOUT going into elif and setting buttonPressed = False again.

I came out with this solution:

buttons, times = mouse.getPressed(getTime=True)

for square in squares:  
    if mouse.isPressedIn(square) and buttons[0] == 1: # left key       

        # do stuff, when left click
   
    elif times[2] != 0 and buttons[2] == 1: # right key   

        # reset button and times
        mouse.clickReset()
        buttons[2] = 0

        # do stuff, when right click
              
mouse.clickReset()

Importantly, the times are positive numbers in psychopy, but negative online on pavlovia!