Typed Responses, getKeys()

Hi, I am a starter with PsychoPy, and this is the first time I asked a question in the Discourse. I have tried to help myself and borrowed code from different posts but it still does not seem to work properly.

My device:
macOS Mojave: version 10.14.6
PsychoPy version: 2020.2.3
Standard Standalone? Yes

What are you trying to achieve?:
I am trying to gather the typed responses of participants for a memory study.

What did you try to make it work?:
The code I am currently using is:

Begin Routine

textFill = ''

Each Frame

pkeys = key_resp.getKeys()
if len(pkeys):
    if 'space' in pkeys:
        textFill += ' '
    elif 'backspace' in pkeys:
        textFill = textFill[:-1]
    elif 'return' in pkeys:
        continueRoutine = False
    else: 
        textFill += pkeys[0]

I have also checked the other settings, the text is set every frame, and the key_resp is storing all the keys.

What specifically went wrong when you tried that?:
Nothing showed up when I used the keyboard. ‘return’ does not work, either.

Extra Information:
I also tried to replace the key_resp.getKeys() with key_resp.keys, the opposite phenomenon seemed to happen. When I typed any letter once, it would repeat endlessly without stopping.

Hope everyone has a nice day!

Hi There!

It looks like you are very close to the solution there, please could I ask if you have tried the code from this post here? Writen response (there are some subtle differences to your code snippet there)

Thanks,
Becca

Have you tried event.getKeys() ?

In version 2020.2 we added a Textbox component which you may be interested in, it allows users to type input in much the same way as a textbox in any other software, storing their text in the experiment output.

Hi, thank you Becca. I have tried their code in the beginning, but when I used it, it usually exited the experiment without anything displaying on the screen.

Hi, I believe the event in my setting is the key_resp.

Hi, thank you for the suggestion. However, I think it is something mysterious wrong with my code, and when I used the Textbox, the same issue occurred…

event is a generic term which needs manual translation in code_JS as per my crib sheet (see pinned post)

1 Like