Keyboard input from last trial flashes briefly on next trial

Hello everyone,

I’m doing an online experiment where people hear words and then have to type them. I have some custom code that interprets their response into a string called refined_response and presents it back to them as they type. It then parses the response to see how many words were typed correctly. Here’s the python code:

L = event.getKeys()
if len(L):
    if 'escape' in L and isPyExp:
        core.quit()
    else:
        for i in L:
            if i in allowedKeys:
                refined_response = refined_response + i
            elif i == 'space' and len(refined_response)>0:
                refined_response = refined_response + ' '
            elif i == 'backspace' and len(refined_response)>0:
                refined_response = refined_response[:-1]

Locally, the code seems to work fine, and the experiment also runs online, except that at the beginning of some trials, the typed response from the previous trial will flash briefly before the recall period begins. This could be distracting to people trying to hold the current words in memory.

I have tried to clear the responses both at the beginning of the recall routine and after logging the response by inserting this code:

PY:

# flush typed words so they don't appear later
clearEvents()
refined_response = ""

JS:

// flush typed words so they don't appear later
psychoJS.eventManager.clearEvents();
refined_response = "";

But the problem still remains. I should note that I’m using PsychoPy 2020.2.4, so the bug fix implemented here by @dvbridges should be incorporated, I think.

Any idea what’s going on? Am I just using the wrong commands to flush, or is this something more fundamental?

Hi There,

In the most recent release of PsychoPy you don’t need custom code to present a typed response - you can use the ‘textBox Beta’ component. Are you able to have a go with this and see if that resolves your problem?

Since this is a common issue on discourse we JUST uploaded a youtube video tutorial on the new textbox component https://youtu.be/a9xQlFx5dOQ (relative to your issue, it shows how to refresh/clear this on each trial)

I hope this is helpful!
Becca

Thanks @Becca, this is definitely a welcome feature. However, I’d like this to be as similar as possible to an experiment I ran back in July, for the participants’ sake but also so I don’t have to re-do my analysis code. I will definitely use this component in the future, but for now is there a workaround for my problem?

Sure, it sounds like the previous text is being presented on the first frame. I assume you are feeding ‘refined_response’ into a text component? in which case can you use the setText(’ ') method (or, x.text = ’ ’ where x is the name of your component) at the end of the previous routine? which tab of your code component do you currently have your code in? :slight_smile:

Thanks,
Becca

Thanks! Adding x.text = ' ' at the beginning of the following routine did the trick. I had to keep the text around to do some operations on it, and then clear it when I was done with that.

fab! pleased it worked