| Reference | Downloads | Github

Measuring response time with mouse component

OS (e.g. Win10): macOS 10.5
PsychoPy version (e.g. 1.84.x): 3.1.5
Standard Standalone? (y/n) Yes
What are you trying to achieve?: I want to measure the response time of the participant clicking a visual.ButtonStim.

What did you try to make it work?: I tried using the mouse component and putting the name of the button stim into the ‘clickable stimuli’ field in the mouse component.

What specifically went wrong when you tried that?: Mouse.time in the output measures the time of any mouse click on the screen, not only on my button stim (which is what I want to achieve).

I am new to PsychoPy and I would be very grateful for any suggestions on how I can achieve this or any insights on what I might not have understood correctly.

Hi @lilly, have you selected to end the routine on “valid click” and set the mouse save state to “final”?

Hi @dvbridges, thank you for your reply. I have not selected to end the routine on “valid click” because this is not supposed to happen as the participants have a certain amount of time for this routine and should be able to change their decision during that time. Is there a way to store the response time of the last click on the button?

If you want the mouse response saving on the button click, you can use the following code in the Each Frame tab of a code component:

if <yourButton>.buttonClicked():
    thisExp.addData("mouse.trial_time", t)  # Save time relative to start of trial
    thisExp.addData("mouse.mouse_time", mouse.mouseClock.getTime())  # Save time relative to start of mouse
    continueRoutine = False

I tried to do this but I got this error message:

 if ButtonLeft.buttonClicked():
TypeError: buttonClicked() missing 1 required positional argument: 'mouse'

Just to be clear what I want to achieve: In this routine, I have two button stims called ButtonLeft and ButtonRight. Participants have eight seconds to click any one of those buttons or press one of them and then change their decision and click the other button. The last button press in this routine is the one that I am interested in as the button that is selected at the end of the routine is the participant’s valid decision.
I appreciate your help!

Ok, well what you can do is:

  • set a time attribute to each button
  • Update time attributes with trial time on each screen refresh
  • Set buttons as clickable stimuli
  • Store params for clicked stimuli i…e, name and new time attribute
  • Save the last stim that was clicked.

The code to do this is:

# Begin Routine
leftButton.time = 0
rightButton.time = 0

# Each Frame
leftButton.time = t
rightButton.time = t

# End Routine
if len(mouse.clicked_name):
    thisExp.addData("clickedButtonName", mouse.clicked_name[-1])
    thisExp.addData("clickedButtonTime", mouse.clicked_time[-1])
    thisExp.addData("clickedButtonName", None)
    thisExp.addData("clickedButtonTime", None)

Mouse component will look like this:

I tried following your steps but I don’t get any data in my output file.

Ohne Titel

Ohne Titel Kopie

I carefully followed your steps but maybe there is something missing?

Ok, did you change the names of the buttons in the code? e.g., leftButton should become ButtonLeft, and same for the mouse component

Yes, I adapted all of the names to match mine.

Ok, would you mind sharing the task to I can take a look? You could upload to Pavlovia and share the link to the project.