Display typed responses

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