Millisecond Forums

Count Button Presses in Trial with Fixed Duration

https://forums.millisecond.com/Topic22895.aspx

By Pete - 11/19/2017

Hi everyone,

I'm trying to create a trial lasting 3 min in which participants have to press the spacebar every time they come up with an idea. I would like to count how many times the participant presses the spacebar and if possible at what exact points in time during the 3 min interval the presses took place. 

I would really appreciate any help as I seem to be stuck.
By Dave - 11/20/2017

Pete - Monday, November 20, 2017
Hi everyone,

I'm trying to create a trial lasting 3 min in which participants have to press the spacebar every time they come up with an idea. I would like to count how many times the participant presses the spacebar and if possible at what exact points in time during the 3 min interval the presses took place. 

I would really appreciate any help as I seem to be stuck.

You can achieve this using /isvalidresponse:

<block ideablock>
/ trials = [1=ideatrial]
</block>

<trial ideatrial>
/ stimulusframes = [1=ideatext]
/ validresponse = (57)
/ isvalidresponse = [if (trial.ideatrial.response == 57) {values.spacebarcount +=1; values.keypresstimes = concat(concat(values.keypresstimes, trial.ideatrial.latency), ";"); false}]
/ timeout = 30000
</trial>

<values>
/ spacebarcount = 0
/ keypresstimes = ""
</values>

<text ideatext>
/ items = ("Press the spacebar whenever you have an idea.")
</text>

<data>
/ columns = [date time subject group blocknum blockcode trialnum trialcode stimulusitem response latency
    values.spacebarcount values.keypresstimes]
/ separatefiles = true
</data>

You'll find the total number of spacebar presses logged in values.spacebarcount; you'll find a list of the exact times when the presses occurred in values.keypresstimes (in milliseconds, measured from the start of the trial).
By Pete - 11/20/2017

Thank you very much! Works perfectly!