Record duration mouse press

Hi guys,

I want to record the duration of a mouse press in my experiment. I thought I had found a pretty straightforward solution that worked offline (see code below), but the duration that is recorded for the online version is always somewhere around 0.167 (1 frame I guess?).

clock is defined at the beginning of the exp (in js code component):
sw = new util.Clock();

Each frame (in py-> auto code component):

if mouse1.isPressedIn(polygonA):

if sound_15.status == STARTED and not mouse1.getPressed()[0]:
t1 = sw.getTime()

Any help would be appreciated.


Ah, I suppose sw only starts running between the press and release of the click? So that’s one frame.

1 Like

This is true (and therefore the clock reset) on every frame that the mouse is pressed. You need to add a flag.

The following might work

if sound_15.status == STARTED and mouse1.getPressed()[0]:
elif sound_15.status == STARTED:
     t1 = sw.getTime()
elif mouse1.isPressedIn(polygonA):

You could add continueRoutine=False below setting t1=0. I’m not sure when you wnat to end the routine.

Yeah thanks, I’ll try this!

Actually, it did not work properly, as it seems that the timer was never reset. I ended up adding an extra bool:

if sound_16.status == STARTED and mouse1.isPressedIn(polygon) and stopwatchStart == True:
elif sound_16.status == STARTED and stopwatchStart == True:
    t1 = sw.getTime()
elif mouse1.isPressedIn(polygon):
    stopwatchStart = True

But thanks for the help, it is much appreciated!