Recording RT from button de-press

Hi all,

Each trial of my task is initiated with a button press (e.g., press and hold the space bar).

E.g., participants press and hold the space bar, an image is then presented, and they release the space bar given task instructions.

I’m wondering if it is possible to use button de-press as a marker of RT.

Any input would be greatly appreciated.

Thanks,
FG

Hi @frankgarcea, if I understand your description correctly, your RT should be identical to the duration the space bar was pressed, right?

If so, this is how you could save key press duration:

# Begin experiment
from psychopy.hardware import keyboard
from psychopy import core

kb = keyboard.Keyboard()

# End routine
keys = kb.getKeys(['space'], waitRelease=True)
key = keys[0] 
thisExp.addData("RT", key.duration)

I have not tested this, so let me know if it works.

1 Like

Hi @ajus – thanks so much for this snippet of code.

I should have provided a bit more context in my initial post. On each trial, a fixation cross is presented and the participant presses and holds a button to advance the trial. An image is then presented and the participant lets go of the button if the image is consistent with task instruction (kind of like a go/no-go task).

So I would need the duration of time between the onset of the image and the de-pressing of the button.

Do you think the code provided would still work in this instance?

Thanks!
FG

If the image appears immediately when the space bar is pressed, the duration of the key press should be pretty much identical to the time from the image onset to the “de-press” of the space bar. So, yes if the code works at all, it should do what you want :smiley:

Maybe try this code. In contrast to my previous suggestion, it clears the keyboard at the beginning of the routine, just in case you use “space” elsewhere before the routine. Also, it ends the routine on the “de-press”, which is probably also what you want to do, right?

# Begin experiment
from psychopy.hardware import keyboard
from psychopy import core

kb = keyboard.Keyboard()

# Begin routine
kb.getKeys(waitRelease = False, clear = True)

# Every frame
keys = kb.getKeys(['space'], waitRelease=True)
if "space" in keys:
    continueRoutine = False

# End routine
key = keys[0] 
thisExp.addData("RT", key.duration)

Hey @ajus - I’m getting the following error…

“/Desktop/ButtonPressTask/ButtonPress_lastrun.py”, line 453, in
key = keys[0]
IndexError: list index out of range

I’m new to PsychoPy, so I’m not sure exactly what’s going on. Perhaps it is not logging the de-press of the space bar?

FG

Hi again @ajus,

Thanks again for your code. I’ve been trying it out and I’ve found that RT is accurately recorded only if I press the space bar. It would appear that PsychoPy is not registering that the button is first de-pressed before it is pressed again.

It also appears that trial level information may be overwritten on every trial. The CSV output only has information from one trial.

I also found this thread: Newbie needs help coding experiment in PsychoPy, then Pavlovia

I’m curious to find out if it’s possible to record de-presses using Builder when running local to one’s machine.

FG

Hi @frankgarcea,

for me, the code works fine, see depress1 below. Is the space bar pressed and released in two different routines? If so, make sure to use the code in “Begin routine” in the first routine and the other code in the second one, see depress2.
depress1.psyexp (12.1 KB)
depress2.psyexp (14.8 KB)

Hey @ajus

Thank you! I used the code in depress2.psyexp to record the space bar de-press relative to the onset of the target image. I appreciate your help!

FG

1 Like