Time response on first key

Hi, in my experiment participants reply to stimuli by writing a word and I would like to record the time it takes them to press the first key. I’m not sure how to do that, especially as I do not have a keyboard response in the experiment (I need the participants to see what they are writing which uses the code and text response). I’ve tried just adding "thisExp.addData(“timereposne”, t), but it gives the time it takes to finish a routine which is not ewhat I want.

this is what I have in the code right now, could you tell me what I should add?

Begin Experiment
import string
allLetters = list(string.ascii_lowercase)
Begin Routine
textFill = ''
Each Frame
keys = event.getKeys()
if 'escape' in keys:
    core.quit()
else:
    if keys:
        if keys[0] == 'space':
            textFill += ' '
        elif keys[0] == 'backspace':
            textFill = textFill[:-1]
        elif keys[0] in allLetters:
            textFill+=keys[0]
        showresponse.setText(textFill)
Each Routine
thisExp.addData("textResponse", showresponse.text)
if showresponse.text.lower() == answercorrect.text.lower():
    correctResp = 1
    thisExp.addData("correct", 1)
else:
    correctResp = 0
    thisExp.addData("correct", 0)

thank you!

You could use the time from the built-in clock:

# Begin routine
firstKeyTime = None  

# Each Frame
keys = event.getKeys()
if 'escape' in keys:
    core.quit()
else:
    if keys:
        if firstKeyTime is None:
            firstKeyTime = t  # Time from routine start to first key press

# End routine
thisExp.appData("firstKeyTime", firstKeyTime)
1 Like