How do I store correct response using left-right button mouse clicks

Hi, a beginner’s question,

I am creating a task in which an arrow appears at the center of the screen. Participants make a right or left mouse click based on its direction.

In the CSV, I see that “mouse.leftButton” and “mouse.rightButton” variables were automatically created and they store 0 if a response wasn’t made and 1 if it was.

I want to use these variables to create another variable that codes a correct answer.

I tried:
‘’‘if mouse.leftButton[0] == 1 and correct_response == “left”:
thisExp.addData(‘correct_ans’, 1)
elif mouse.rightButton[0] == 1 and correct_response == “right”:
thisExp.addData(‘correct_ans’, 1)
else:
thisExp.addData(‘correct_ans’, 0)’’’

However, I get the error message: AttributeError: ‘Mouse’ object has no attribute ‘leftButton’

I’ll appreciate any help with this.

Noam

1 Like

I think the attribute you want here is getPressed. This will tell you whether buttons 0,1 and 2 (Left, Middle and Right) are currently pressed via a list with three bools - either True or False for each.

Thanks so much!

1 Like