# How to save response time when running an experiment with a touchscreen

**URL:** <https://discourse.psychopy.org/t/how-to-save-response-time-when-running-an-experiment-with-a-touchscreen/22936>\
**Category:** Builder\
**Created:** [May 12, 2021, 5:11am UTC](https://discourse.psychopy.org/t/how-to-save-response-time-when-running-an-experiment-with-a-touchscreen/22936 "2021-05-12T05:11:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![petrichornaluy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/petrichornaluy/32/16178_2.png) [@petrichornaluy](https://discourse.psychopy.org/u/petrichornaluy)\
**Post date:** [May 12, 2021, 5:11am UTC](https://discourse.psychopy.org/t/how-to-save-response-time-when-running-an-experiment-with-a-touchscreen/22936/1 "2021-05-12T05:11:34Z")

</div>

**OS** : Win10  
**PsychoPy version** : 2021.1.4  
**Standard Standalone?** : Yes

Hi all! I am quite new at Psychology and programming in Psychology. I am trying to run an experiment with a touchscreen and Michael’s code has solved the problem about double-click/swipe.  
[Writing contains(mouse) to output](https://discourse.psychopy.org/t/writing-contains-mouse-to-output/4808)

In my experiment, the participants have to select one of the five choices (I used polygons here) after they saw a picture(video). There are 160 pictures(videos) and I would like to let them rest after they saw 20 pictures(videos). Since there are no right answers, all I want to know is which button the participant selects and their response time on pressing the button. However, I have no idea what I should do to collect response time.

I tried the code but “clicked\_resp\_time” seems quite weird (because it is much longer than the time clicked by a mouse)…

 ![屏幕快照 2021-05-11 21.36.55](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/a/dac47d852801fd55d50f9eae51e5f6a827583099.png)

The following is my code component:  
**Begin Experiment**

```auto
trialscounter = 1
import psychopy.event
mouse = psychopy.event.Mouse(win=win)
from pyschopy import iohub
from psychopy import clock, core

```

**Begin Routine**

```auto
rest = False
mouseclick = False
timer = core.CountdownTimer(1000)
stimuli = [pressframeshita, turnframeshita, pullframeshita, slideframeshita, naiframeshita]
mouse = mouse
mouse.setPos(newPos=(0,0))
mouserec=mouse.getPos()

```

**Each Frame**

```auto
if trialscounter % 20 == 0:
    if mouse.isPressedIn(pressframeshita) or mouse.isPressedIn(turnframeshita) or mouse.isPressedIn(pullframeshita) or mouse.isPressedIn(slideframeshita) or mouse.isPressedIn(naiframeshita)
     rest = True
     mouseclick = True
     timer = core.CountdownTimer(1)

else:
    if mouse.isPressedIn(pressframeshita) or mouse.isPressedIn(turnframeshita) or mouse.isPressedIn(pullframeshita) or mouse.isPressedIn(slideframeshita) or mouse.isPressedIn(naiframeshita)
     continueRoutine = False

if mouseclick == True:
     if timer.getTime()<0:
     if mouse.isPressedIn(image_3): #have a rest per 20 trials
      continueRoutine = False

mouseloc = mouse.getPos()

for stimulus in stimuli:
    if stimulus.contains(mouse):
        mouserec = mouseloc
        mousetime = core.getTime()
        thisExp.addData('clicked_stimulus', stimulus.name)
        thisExp.addData('clicked_stimulus', mousetime)
        continueRoutine = False

```

**End Routine**

```auto
trialscounter = trialscounter + 1

```

I will greatly appreciate that if anyone can tell me the solution in more detail. Thank you!

Best,  
Petrichornaluy

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [May 12, 2021, 5:31pm UTC](https://discourse.psychopy.org/t/how-to-save-response-time-when-running-an-experiment-with-a-touchscreen/22936/2 "2021-05-12T17:31:29Z")

</div>

Hi There,

in builder making sure you save the data from the mouse component “onclick” will save the data (more accurately a list of RTs for each click)
