Here’s the Python code from one of my experiments.
Begin Routine
modify = False
displayText=''
oldDisplayText=''
event.clearEvents()
cursorCounter=0
cursorVariable='_'
textStarted=0
myClock.reset()
Each Frame
if cursorCounter >= 30:
if cursorVariable=='_':
cursorVariable=' '
else:
cursorVariable='_'
cursorCounter=0
cursorCounter+=1
keys = event.getKeys()
if len(keys):
#Start the clock on first key
if textStarted == 0:
textStarted = 1
rt0=myClock.getTime()
myClock.reset()
if 'return' in keys and len(displayText)>1:
rt1=myClock.getTime()
continueRoutine=False
elif 'space' in keys:
displayText+=' '
elif 'period' in keys:
displayText+='.'
elif 'comma' in keys:
displayText+=','
elif 'apostrophe' in keys:
displayText+='\''
elif 'minus' in keys:
displayText+='\-'
elif 'backspace' in keys:
displayText=displayText[:-1]
elif 'lshift' in keys or 'rshift' in keys:
modify = True
elif len(keys[0])>1:
pass
elif modify==False:
displayText += keys[0]
End Routine
thisExp.addData("typedWords", displayText)
thisExp.addData("thinkingTime", rt0)
thisExp.addData("typingTime", rt1)
text_feedback.text='Thinking time = '+str(round(rt0,2))+'s\nTyping time = '+str(round(rt1,2))+'s\n'+displayText