psychopy.org | Reference | Downloads | Github

How to temporarily hide text responses

Hello,

I am currently having difficulty when I try to temporarily disable the keyboard response. I am trying to design an experiment where the participant has to wait 5 seconds to respond after the stimulus is presented. During this period, I have inserted an image that will be appear for 5 seconds. It is a verbal working memory task so I don’t want the participant to be able to touch/register any keys until the image disappears.

However, during the trials, any keys that are pressed before the image is finished will still appear on the screen. How do I set it so that the keyboard can be temporarily frozen until the delay period is over?

These are the codes I have chosen:

Begin routine:
modify = False
text.text = ‘’
event.clearEvents(‘keyboard’)

Each frame:
image.status==FINISHED

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
else:
if modify:
text.text = text.text + keys[0].upper()
modify = False
else:
text.text = text.text + keys[0]

image.status==FINISHED - This code has worked to allow excel to only register the text after the image - this is what I want. But what I don’t want is for the text (or return key) to be activated until this image finishes. Thank you in advance.

Hi @Frank99,

your post is difficult to read. Help us to help you by surrounding your code with backticks to preserve indentation.

Without reading your code too closely (because it is difficult to understand in this format), I see that you check the keyboard and then update a text component’s text attribute. You could check a timer and only query the keyboard, if the timer says that the 5 secs are over. Would that solve the problem?

Hi @LukasPsy,

Thank you for your this. This should make it clearer for you to see.

Begin Routine
modify = False
text.text = ''
event.clearEvents('keyboard')
Each frame
image.status==FINISHED

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
    else:
        if modify:
            text.text = text.text + keys[0].upper()
            modify = False
        else:
            text.text = text.text + keys[0]

I am new to Psychopy so I’ve been doing a lot of trial & errors but I can’t manage to get the keyboard responses to disappear/temporarily freeze. Could you inform me which position this timer can be included here?

Every frame the builder automatically calls t = NameOfYourTrialHandler.getTime(). You can use this t variable to check when 5 secs have passed:

if t >= 5: 
    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
        else:
            if modify:
                text.text = text.text + keys[0].upper()
                modify = False
            else:
                text.text = text.text + keys[0]
1 Like

This has worked, thank you!

However there is one more problem now. If I press keys during this delay period (e.g. ‘34567’). The first key I enter is still appearing, so in this case ‘3’. Also, if I touch the ‘return’ key at all during this period (e.g. ‘345return’), once the 5s delay is over it will automatically proceed to the next trial. Do you know why this is happening?

You’ll have to clear the event buffer:
In the begin routine tab:

eventBufferCleared = False

Then in the each frame tab:

if t >= 5: 
    if not eventBufferCleared: event.clearEvens(); eventBufferCleared = True
    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
        else:
            if modify:
                text.text = text.text + keys[0].upper()
                modify = False
            else:
                text.text = text.text + keys[0]
1 Like

Great it’s working perfectly now. I really appreciate your help!

1 Like