# Unable to get response time from mouse clicks in an online experiment

**URL:** https://discourse.psychopy.org/t/unable-to-get-response-time-from-mouse-clicks-in-an-online-experiment/11518
**Category:** Online experiments
**Created:** [March 16, 2020, 10:15am UTC](https://discourse.psychopy.org/t/unable-to-get-response-time-from-mouse-clicks-in-an-online-experiment/11518 "2020-03-16T10:15:45Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Omidrezaa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/omidrezaa/32/6105_2.png) [@Omidrezaa](https://discourse.psychopy.org/u/Omidrezaa)
#### Post date: [March 16, 2020, 10:15am UTC](https://discourse.psychopy.org/t/unable-to-get-response-time-from-mouse-clicks-in-an-online-experiment/11518/1 "2020-03-16T10:15:45Z")

</div>

Hi all,

In an online experiment, participants need to click on one of the two boxes and I set the mouse to force end the routine and to set mouse state `on click`. However, when I checked the data, it seems that it saves the first click, no matter if that click was on the valid stimuli or not.

How can I get RT from mouse clicks on valid stimuli in online experiments?

---

<div class="post-metadata">

### Author: ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)
#### Post date: [March 16, 2020, 2:06pm UTC](https://discourse.psychopy.org/t/unable-to-get-response-time-from-mouse-clicks-in-an-online-experiment/11518/2 "2020-03-16T14:06:55Z")

</div>

What is your Save Mouse State set to? If you want click times you might need to set it to On Click:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/a/cafce8340ea114c727fb210ac78428b222c9e085.png)

---

<div class="post-metadata">

### Author: ![Omidrezaa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/omidrezaa/32/6105_2.png) [@Omidrezaa](https://discourse.psychopy.org/u/Omidrezaa)
#### Post date: [March 16, 2020, 2:41pm UTC](https://discourse.psychopy.org/t/unable-to-get-response-time-from-mouse-clicks-in-an-online-experiment/11518/3 "2020-03-16T14:41:47Z")

</div>

Thanks @jon. I already set it to `On Click` as you can see below. But the issue is that it saves the first click not the last one. So if I click on the screen after 2 seceonds nad then on clickable stimuli after 10 seconds, it saves 2.0 in the data file. How can I get the final click RT that ends the routine?  
 ![Untitled](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/1/c194aff8a3726f0cb60296f73416b216c597ebe7.png)

---

<div class="post-metadata">

### Author: ![agleontyev](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/agleontyev/32/1416_2.png) [@agleontyev](https://discourse.psychopy.org/u/agleontyev)
#### Post date: [March 16, 2020, 2:52pm UTC](https://discourse.psychopy.org/t/unable-to-get-response-time-from-mouse-clicks-in-an-online-experiment/11518/4 "2020-03-16T14:52:10Z")

</div>

I am not a specialist in that, but you might want to make it save “every frame” and just take the final ones in the trials you need.

---

<div class="post-metadata">

### Author: ![Omidrezaa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/omidrezaa/32/6105_2.png) [@Omidrezaa](https://discourse.psychopy.org/u/Omidrezaa)
#### Post date: [March 17, 2020, 2:48am UTC](https://discourse.psychopy.org/t/unable-to-get-response-time-from-mouse-clicks-in-an-online-experiment/11518/5 "2020-03-17T02:48:30Z")

</div>

Thanks for your help. Actually, this option gives me RT for all clicks and I do not want all of those. It is difficult to extract the final one from a list of RTs in a file.

---

<div class="post-metadata">

### Author: ![agleontyev](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/agleontyev/32/1416_2.png) [@agleontyev](https://discourse.psychopy.org/u/agleontyev)
#### Post date: [March 17, 2020, 5:44pm UTC](https://discourse.psychopy.org/t/unable-to-get-response-time-from-mouse-clicks-in-an-online-experiment/11518/6 "2020-03-17T17:44:08Z")

</div>

on the data analysis stage? It can be very easily done using mousetrap package.

---

<div class="post-metadata">

### Author: ![Omidrezaa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/omidrezaa/32/6105_2.png) [@Omidrezaa](https://discourse.psychopy.org/u/Omidrezaa)
#### Post date: [March 18, 2020, 12:44am UTC](https://discourse.psychopy.org/t/unable-to-get-response-time-from-mouse-clicks-in-an-online-experiment/11518/7 "2020-03-18T00:44:28Z")

</div>

@agleontyev,

I think this is the only way then. I will use the method that you proposed. And thanks for recommending the package.

---

<div class="post-metadata">

### Author: ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)
#### Post date: [March 18, 2020, 10:49am UTC](https://discourse.psychopy.org/t/unable-to-get-response-time-from-mouse-clicks-in-an-online-experiment/11518/8 "2020-03-18T10:49:57Z")

</div>

If you need an alternative custom check/output then you can always add that in does what you want. For instance it might be something like (untested):

End of Routine code:

```python
if mouse_main.time:
    thisExp.addData('finalClickTime', mouse_main.time[-])

```

That code creates a new column in your data file (finalClickTime) and fetches the last entry in the time attribute (the -1 index is the final one) only if there was at least one entry.

If you compile the experiment to its python script and look at the code already written about your mouse object then you’ll be able to refine the toy code above to do what you need. But it should be something as simple as that. Then you can paste your code back into a code component

---

<div class="post-metadata">

### Author: ![Omidrezaa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/omidrezaa/32/6105_2.png) [@Omidrezaa](https://discourse.psychopy.org/u/Omidrezaa)
#### Post date: [March 18, 2020, 11:24am UTC](https://discourse.psychopy.org/t/unable-to-get-response-time-from-mouse-clicks-in-an-online-experiment/11518/9 "2020-03-18T11:24:55Z")

</div>

Dear @jon. That was brilliant. Using this code, I can extract the final rt from the list of rts. I just made some changes to make it a JS code for those who has a same problem:

```auto
if (mouse_main.time) {
    psychoJS.experiment.addData("final_response_rt", mouse_main.time.slice((- 1))[0]);
}

```

Thank you.
