| Reference | Downloads | Github

Displaying participant responses

I am creating an experiment in which participants are shown lists of words and then later asked to recall as many words as they can by typing them. What I am trying to figure out is how to get all of the words that the participants type in to show up at the same time on the screen, in columns (like a list). Right now I only am able to get one word to show up at a time. I’m not really sure how to go about this. Here is the code that I’m using:

The first thing I have is the keyboard, named “Indi_response”, in which all characters are allowed, and all characters are stored. I have this set at constant.

Then I have a keyboard for an enter key which ends the routine.
Next, I have this code:

#In begin experiment:
msg=' '

#In each frame:
if templist.count('return')==1:
elif templist.count('space')==1:
elif templist.count('lshift')==1:
elif templist.count('backspace')>=1 and len(Indi_response.keys)>=2:
elif templist.count('backspace')>=1 and len(Indi_response.keys)==1:
elif (len(Indi_response.keys)-1) == numkeys:

Finally, I have a text component that displays $msg (which is defined in the code), and is set to every frame.

Any ideas on how to fix this to display all responses?

1 Like

Thank you. I have edited my post.

(1) What separates words? e.g. At the moment, the trial ends when 'return' is pressed (and it is unclear why you would be trying to have a second keyboard component trying to handle this, when it is already being done in code)

(2) Don’t have a second keyboard component. This will lead to very unpredictable behaviour, as the second will only be able to capture keys that have occurred in the very few milliseconds (or even microseconds) since the code for the previous keyboard component was executed, whereas, the first will capture keys from most of the preceding screen refresh period.

I actually didn’t realize that I had the trial being ended in two different places. I was following a template that a predecessor in my lab handed down. I would like to have something like ‘space’, ‘return’ or ‘tab’ separate the words. I will definitely get rid of the second keyboard component. Thank you for the tip.

OK, so if you leave the code as above, then 'return' will end the trial. If you want to use 'space' to delineate words, then make a change like this in your code:

elif templist.count('space')==1:
    # remove the space character:
    # replace it with a newline character to separate words:

By adding a newline character, you should get the words displayed in a column as desired (i.e. each word in its own row), rather than a continuous stream.

Thank you so much! This worked perfectly.

Hi @willi4cm,

I am trying to do something similar I think, but simpler: just want to show subjects math questions and allow them to type a response and see it as they type (before hitting enter to finalize it).

Could I trouble you to please share this bit of code? I.e., the surrounding “frame” part this is imbedded in. (While loop? Somehow attached to the flip.display command?)

…and this bit, to lend context? (New user, so it would just help to be able to connect this with familiar components in the code.)

Thank you kindly.

All the code you need is shared above. “Frame” here refers to the Each frame tab of a Code Component dialog in Builder. i.e the code component provides tabs for code that runs at specified times in the experiment (e.g. at the beginning or end of the experiment, the start or end of the routine, or on every frame (screen refresh)).

In the code above, keypresses are detected and added to a variable called msg, and some editing is allowed with the backspace key. This variable will be displayed on screen if you put $msg in the text field of a Text component, and set that field to update every frame.

Got it. Thanks @Michael.

(For others, who might be new/stuck like me: I was getting confused between the Coder/Builder views. I realized that, in the Builder, he’s creating a Code component–like a Text or Keyboard component–and then inserting the code mentioned into the tabs in the code component called “Begin Experiment”, “Begin Routine”, etc.)


I’m also doing something similar in PsychoPy 3 (PC). I’d like my participants to be able to type multiple words in a single column (up to 8, for example) and I’d like to collect these words in a column in the csv data file. However, when I test it, it does two odd things:

  1. It deletes the last letter of the word just typed
  2. Although it starts a new line for the second word typed, it reverts back to a single line and “space” is inserted instead of nothing.

What am I missing? Should I be using display.text instead of what I’m doing?

if templist.count('return')==1:
 thisExp.addData("recall_resp", screentext)
elif("space" in key_resp.keys):
 thisExp.addData("recall_resp", screentext)
elif templist.count('backspace')>=1 and len(key_resp.keys)>=2:
elif templist.count('backspace')>=1 and len(key_resp.keys)==1:
elif (len(key_resp.keys)-1) == numkeys:

screentext = ''.join(key_resp.keys)