# Presenting stimuli based on keyboard response

**URL:** <https://psychtoolbox.discourse.group/t/presenting-stimuli-based-on-keyboard-response/3057>\
**Category:** Programming Help\
**Tags:** windows\
**Created:** [February 17, 2020, 5:47pm UTC](https://psychtoolbox.discourse.group/t/presenting-stimuli-based-on-keyboard-response/3057 "2020-02-17T17:47:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RAM](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ram/32/46_2.png) [@RAM](https://psychtoolbox.discourse.group/u/RAM)\
**Post date:** [February 17, 2020, 5:47pm UTC](https://psychtoolbox.discourse.group/t/presenting-stimuli-based-on-keyboard-response/3057/1 "2020-02-17T17:47:21Z")

</div>

Is there any keyboard response function in PTB which takes a string as a keyboard response,say ‘ABC’ instead of just a single key and use that as condition to present an image.

---

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [February 18, 2020, 6:11am UTC](https://psychtoolbox.discourse.group/t/presenting-stimuli-based-on-keyboard-response/3057/2 "2020-02-18T06:11:41Z")

</div>

Not that I know of, but it should be fairly straightforward to write. Simplest of course is just 3 `KbWait` calls, but more flexible are the `Kbqueue` functions: read `>>doc KbQueueCreate` and use these various functions to create a keyboard queue, `KbQueueCheck` returns a list of which keys were pressed when (all keyboard functions use a 256 long table, use `KbName` to find which key maps to which number). You can then make sure it follows the order you want, and if it matches then you can show your image.

---

<div class="post-metadata">

**Author:** ![RAM](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ram/32/46_2.png) [@RAM](https://psychtoolbox.discourse.group/u/RAM)\
**Post date:** [February 18, 2020, 6:35am UTC](https://psychtoolbox.discourse.group/t/presenting-stimuli-based-on-keyboard-response/3057/3 "2020-02-18T06:35:18Z")

</div>

thanks 🙂

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [February 18, 2020, 8:23am UTC](https://psychtoolbox.discourse.group/t/presenting-stimuli-based-on-keyboard-response/3057/4 "2020-02-18T08:23:59Z")

</div>

That solution would only work if each key is to appear once. Perhaps  
`help GetString` is what you are looking for? There is also  
`GetEchoString` if you want to make what is typed visible

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [February 18, 2020, 11:47am UTC](https://psychtoolbox.discourse.group/t/presenting-stimuli-based-on-keyboard-response/3057/5 "2020-02-18T11:47:50Z")

</div>

There’s GetEchoString() and Ask() (if you set the replyfun parameter to ‘GetChar’) for that. It’s very basic, for simple word entry.
