psychopy.org | Reference | Downloads | Github

Show the key response

If this template helps then use it. If not then just delete and start from scratch.

OS: Win10
PsychoPy version: 1.90.1
What are you trying to achieve?:
Participants are shown an artificial word and they have to type in what it means in English. I want the answer they are typing in to show on the screen so that participants can see what they are doing and be able to edit it.

What did you try to make it work?:
I tried some code components, but it isn’t working so I’m not even going to put those in, because I’m definitely doing it wrong.

What specifically went wrong when you tried that?:
I have no error message, but nothing shows up on the screen when I type.

Hi @smile667, take a look at this link below, the code in the code component allows users to type on screen in real time using a text component in Builder.

1 Like

hi @dvbridges , thank you for that, it does show on the screen now. but now I have no way of tracking what keys were pressed and if the information entered was correct without which is my DV. is it possible to change that?

Ok, you just want the final text that was written from the text component and write the text to the data file. In the code component, in the End Routine tab:

thisExp.addData("textResponse", textComponent.text)  # Where textComponent is the name of your text component

@dvbridges thank you very much, it shows in the data now. Just one more issue on this subject, is there anyway for the entered text to show up as correct or not In the data? I have to give feedback to participants and I cannot do that if there is no “correct response” column in the data (at least I think I can’t).

Sure, it will be a matter of comparing strings between your expected answer and the text component text. If case does not matter, it is a simple bit of code:

# End routine tab

if text.text.lower() == yourAnswer.lower():
    correctResp = 1
else:
    correctResp = 0

In your feedback code, you can write:

if correctResp:
    msg = "Correct"
else:
    msg = "Incorrect"
feedbackText.setText(msg)  # Your feedback text component
1 Like

@dvbridges thank you so much, everything works now.

Hello,

I have a very similar code component to @smile667 and I also want participants to see what they type while the word they need to type is displayed on the screen.

For info, I am using PsychoPy 2020.2.1 standalone version on MacOS 11.1.

My issue is that what participants type appends directly onto the end of the visible word. For example, if the word they need to type is ‘stutter’, this word is displayed on the screen and when the participant types ‘stutter’ it will appear like this:
‘stutterstutter’

What I want is the word ‘stutter’ to appear at the bottom of the screen but what participants type to appear in the middle of the screen .

@dvbridges can you help?

My code component at the moment is as follows:
Begin routine:

modify = False
text.text = ' '
event.clearEvents('keyboard')
RTs=[]

Each frame:

keys = event.getKeys()
if len(keys):
    RTs.append(t)
    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 have tried adding in the following into the ‘Each Frame’ tab without any luck:

keys.pos = (0,0)

Any help would be hugely appreciated!

SOLVED - I also had the word showing up in a text component which is why anything being typed had the appearance of appending directly onto the end of whatever was displayed in the text component! Once I made sure the text component was blank it worked fine!