Wait until mouse click

Hi everyone,
In my experiment, I would like to have something like this.
If I click on a rating scale 0 tick mark, the solenoid valve will turn on and off until I click on another tick mark. If I click on a rating scale 1 tick mark, another solenoid valve will turn on and off until I click on the first tick mark. This operation will tack place till pre-defined count down timer reaches to 0.
I am having trouble with the mouse click. How can I use mouse.getPressed () function? I do not know what is the return of this function, so I am not able to use while loop with == or != operator. The document says ‘Returns a 3-item list indicating whether or not buttons 0,1,2 are currently pressed.’ I do not have any idea what does that means.

 timer = core.CountdownTimer (myTimer)
 while (timer.getTime() > 0): 
           
            myRatingScale12.draw()
            instruction1.draw()
            win.flip()
            rating12 = myRatingScale12.getRating()
            
            if rating12 == 0:
            Here I would like to have while loop which runs until the mouse click 
                   command = arduino.write(struct.pack(u'>H',257)) 
                   time.sleep (3)
                   command = arduino.write(struct.pack(u'>H',256))
            myRatingScale12.reset()
            
            elif rating12 == 1:
            Here I would like to have while loop which runs until the mouse click 
                  command = arduino.write(struct.pack(u'>H',4097)) 
                  time.sleep (3)
                  command = arduino.write(struct.pack(u'>H',4096))
            myRatingScale12.reset()

HI @RaviMevada, ‘Returns a 3-item list indicating whether or not buttons 0,1,2 are currently pressed.’ means that when mouse.getPressed() is called, it returns a three item list e.g., [0, 0, 0] where each element of the list refers to one of the mouse buttons (0 = left mouse mutton, 1 = middle mouse button, 2=right mouse button).

If you want to check whether a rating was clicked, you would use something like:

if myRatingScale.getRating() == 0 and mouse.getPressed()[0] == 1:
    # do something

1 Like

Hi @dvbridges,
Thank you very much. By using mouse.getPressed()[0]==1:. It is working exactly the way I want.

1 Like