Measuring the duration of a button press

Hi All, I am using superlab 5 and as part of the experiment I want to measure the duration that participants press the spacebar key for. Is there any way I can do this?

Thanks!

  • Uncheck the Ignore the key release option in Participant Input.

  • Create a response for both pressing and releasing the space bar.

  • Create a timer parameter to measure the duration of the space bar being pressed.

  • In your events, set feedback so that pressing the space bar starts the timer and releasing the space bar pauses the timer.

I’ve attached an example experiment for you to use as reference.

keyPressTimer.sl5 (4.33 KB)

1 Like

Hi Arman,

Thank you so much for your response. I cant seem to open your file for some reason?! I have followed your instructions though and for some reason only the start time that the spacebar button is pressed is being saved…the duration that the button is pressed for (ie, when it is released) is not recording. Also, I would like the event to remain on screen for 5 minutes, ie, so I can record several times that the button is pressed…by adding the parameter it seems to end the event after the spacebar is released (even though I have requested that the trial only end after a certain time)…sorry for all the questions!

I’ve attached a zip of the experiment file. Hopefully, this will work for you.

In the attached experiment, you’ll see that the timer value is displayed in another trial. This is because parameter values are only updated once the trial in which they are modified ends. This may be why it seems the duration is not being recorded.

As for the trial remaining for 5 minutes, this should be possible. Can you further explain your experimental design? This will give me more to work with.

keyPressTimer.zip (1.75 KB)

Hi Arman,

thank you so much for getting back to me! I will try and open the file you have sent and hopefully it will work!

Participants are asked to think or avoid thinking about a particular thought for five minutes…whenever they think of that thought they will be required to press the spacebar and hold it down until they think of something else…so this is why I would need the event to remain for five minutes…hope this helps!

Thank you!

In that case, you may want to loop the block in the experiment I sent you. Also, set it to stop presenting trials after five minutes.

Let me know how it goes once you’ve worked with it a bit.