Thanks Michael. Looked like it would do the trick but I was hoping for something simpler to hand over to a non-programming researcher so I had a play and came up with the following which satisfies my requirements.
I've stuck the code into GitHub here https://github.com/jacanterbury/PsychoPy-snippets
but basically it does the following:
TextStim text field contains this:
$(word + '\n' + inputText)
A code object in the same loop has this:
Begin Experiment:
inputText = ""
Begin Routine:
theseKeys=""
shift_flag = False
text_3.alignHoriz ='left'
Each Frame:
n= len(theseKeys)
i = 0
while i < n:
if theseKeys[i] == 'return':
# pressing RETURN means time to stop
continueRoutine = False
break
elif theseKeys[i] == 'backspace':
inputText = inputText[:-1] # lose the final character
i = i + 1
elif theseKeys[i] == 'space':
inputText += ' '
i = i + 1
elif theseKeys[i] in ['lshift', 'rshift']:
shift_flag = True
i = i + 1
else:
if len(theseKeys[i]) == 1:
# we only have 1 char so should be a normal key,
# otherwise it might be 'ctrl' or similar so ignore it
if shift_flag:
inputText += chr( ord(theseKeys[i]) - ord(' '))
shift_flag = False
else:
inputText += theseKeys[i]
i = i + 1
End Routine:
# let's store the final text string into the results finle...
thisExp.addData('inputText', inputText)
inputText=""
The results file in the data folder gives the individual keys pressed as well as the final string
Hopefully the code is fairly self-explanatory. The only thing that might not be obvious is that the lower & upper case characters in ascii are 1:1 & 32 apart which is the value of a single white space (e.g. in ASCII 'a' = 'A' + ' ' )
Feel free to comment/improve on it (it doesn't handle SHIFT-LOCK at present but that should be easy to fix)
Would be nice to drop it into a library so that all the code on the 'Each Frame' tab could be swapped for a single line