Display typed responses

Hello,

I found solutions how to display typed responses using Builder, but I have trouble finding functions to do that in Coder…
While presenting a question something like this,

instructionStr = "Type answer here"
instText = visual.TextStim(myWin, text=instructionStr, pos=(0,0), color=(-1,-1,-1), height=0.1)

I want to display typed keyboard responses (word) on the same screen.
What function of PsychoPy in Coder can accomplish it?

Thank you.

Here’s a very simple one:

typedText = ''
textEntryCompleted = False
showText = visual.TextStim(myWin, text=typedText, pos=(0,-.5), color=(-1,-1,-1), height=0.1)
while not textEntryCompleted:
    keyPressed = event.waitKeys()
    if 'return' in keyPressed:
        textEntryCompleted = True
    elif 'space' in keyPressed:
        typedText = typedText + ' '
    else:
        typedText = typedText + keyPressed[-1]
   
    showText.text = typedText
    showText.draw()
    myWin.flip()

This doesn’t work with uppercase/lowercase stuff, but that is also possible using the ‘modifiers=True’ argument in event.waitKeys() and the Python string function .upper(), but the logic is a little more complicated.

1 Like