How can I have capslock on for the entire response?

Hi all,

I am working on an experiment where participants need to type responses to a stimulus in capital letters. I am using the most recent version of Psychopy. With the current code that I have, I am able to have capitalization using capslock, but you have to press capslock for every individual letter- it is behaving like a shift key. This is the code I have right now:

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 'capslock' in keys:
        modify = True
    elif 'return' in keys:
        continueRoutine = False
    else:
        if modify:
            text.text = text.text + keys[0].upper()
            modify = False
        else:
            text.text = text.text + keys[0]

I need the capslock key to work for all letters when pressed once. Thank you!

I think the reason you’re having to reset on each press is that you’re setting modify to True on a caps lock press, but then setting it to False again after one letter. To make it toggle, set modify to False before any of this happens and then replace the elif 'capslock bit with modify = not modify to flip it.

However, have you tried the new Textbox component? If you’re looking to include a text input then this is usually a better way of doing it - and it handles capslock natively.

Hi!
I tried this method and it’s still behaving the same (the letter will capitalize every time you press capslock, so it’s still similar to the shift key).
I actually am using the Textbox component, but my issue with it was that whenever I pressed capslock, it would put ‘capslock’ up on the screen and not change the letter, which is why I decided to use some code instead.