| Reference | Downloads | Github

event.getKeys() returns period and comma instead of . and ,

I am trying to create an experiment that involves participants entering free text. I have successfully utilized the code from this example:

However one small issue remains: When participants enter a period or a comma, those words “period” “comma” are printed to screen instead of the symbols. This also happens when CTRL or ALT are pressed. Does anyone see a simple solution to avoid this from happening? I would be willing to block out the use of those keys if necessary.

Below is the code for Begin Routine:

modify = False
text.text = ''

… and for Each Frame:

keys = event.getKeys()
if len(keys):
    if 'space' in keys:
        text.text = text.text + ' '
    elif 'backspace' in keys:
        text.text = text.text[:-1]
    elif 'lshift' in keys or 'rshift' in keys:
        modify = True
    elif 'return' in keys:
        continueRoutine = False
        if modify:
            text.text = text.text + keys[0].upper()
            modify = False
            text.text = text.text + keys[0]

A similar issue has been recently resolved here: Typed response: punctuation