# Typed Responses, getKeys()

**URL:** <https://discourse.psychopy.org/t/typed-responses-getkeys/16188>\
**Category:** Builder\
**Created:** [September 3, 2020, 7:32am UTC](https://discourse.psychopy.org/t/typed-responses-getkeys/16188 "2020-09-03T07:32:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kuriko](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/kuriko/32/10435_2.png) [@Kuriko](https://discourse.psychopy.org/u/Kuriko)\
**Post date:** [September 3, 2020, 7:32am UTC](https://discourse.psychopy.org/t/typed-responses-getkeys/16188/1 "2020-09-03T07:32:09Z")

</div>

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

```auto
textFill = ''

```

> Each Frame

```auto
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!

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [September 3, 2020, 8:09am UTC](https://discourse.psychopy.org/t/typed-responses-getkeys/16188/2 "2020-09-03T08:09:57Z")

</div>

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](https://discourse.psychopy.org/t/writen-response/4676/2) (there are some subtle differences to your code snippet there)

Thanks,  
Becca

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [September 3, 2020, 2:11pm UTC](https://discourse.psychopy.org/t/typed-responses-getkeys/16188/3 "2020-09-03T14:11:33Z")

</div>

Have you tried event.getKeys() ?

---

<div class="post-metadata">

**Author:** ![TParsons](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tparsons/32/8301_2.png) [@TParsons](https://discourse.psychopy.org/u/TParsons)\
**Post date:** [September 3, 2020, 3:06pm UTC](https://discourse.psychopy.org/t/typed-responses-getkeys/16188/4 "2020-09-03T15:06:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kuriko](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/kuriko/32/10435_2.png) [@Kuriko](https://discourse.psychopy.org/u/Kuriko)\
**Post date:** [September 3, 2020, 7:22pm UTC](https://discourse.psychopy.org/t/typed-responses-getkeys/16188/5 "2020-09-03T19:22:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kuriko](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/kuriko/32/10435_2.png) [@Kuriko](https://discourse.psychopy.org/u/Kuriko)\
**Post date:** [September 3, 2020, 7:35pm UTC](https://discourse.psychopy.org/t/typed-responses-getkeys/16188/6 "2020-09-03T19:35:22Z")

</div>

Hi, I believe the event in my setting is the key\_resp.

---

<div class="post-metadata">

**Author:** ![Kuriko](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/kuriko/32/10435_2.png) [@Kuriko](https://discourse.psychopy.org/u/Kuriko)\
**Post date:** [September 3, 2020, 7:36pm UTC](https://discourse.psychopy.org/t/typed-responses-getkeys/16188/7 "2020-09-03T19:36:36Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [September 3, 2020, 8:12pm UTC](https://discourse.psychopy.org/t/typed-responses-getkeys/16188/8 "2020-09-03T20:12:48Z")

</div>

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