# Keyboard Input Mistaken as MATLAB Command

**URL:** <https://psychtoolbox.discourse.group/t/keyboard-input-mistaken-as-matlab-command/4041>\
**Category:** Programming Help\
**Tags:** linux\
**Created:** [September 29, 2021, 5:50pm UTC](https://psychtoolbox.discourse.group/t/keyboard-input-mistaken-as-matlab-command/4041 "2021-09-29T17:50:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![szcody](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@szcody](https://psychtoolbox.discourse.group/u/szcody)\
**Post date:** [September 29, 2021, 5:50pm UTC](https://psychtoolbox.discourse.group/t/keyboard-input-mistaken-as-matlab-command/4041/1 "2021-09-29T17:50:09Z")

</div>

Hello,

I’m currently running a speech recognition task w/ PTB 3.0.15 in MATLAB R2019a on a Linux machine(Ubuntu 18.04). After the stimuli are displayed, we ask the subject to type out their response using the command displayed below.

_DrawFormattedText(win, ‘What did the speaker say?’, ‘center’, ‘center’,[255 255 255]);_  
_[reply{trial\_i},terminatorChar] = GetEchoString(win,’ ',805,575,[255 255 255],[0 0 0]);_

While the subjects’ responses are saved, at the end of the experiment, all the responses they typed out were evaluated by MATLAB as commands, and it’s just annoying… Here’re the errors:

_Did you mean:_  
_Undefined function or variable ‘you’._

- 
  - 

_Did you mean:_  
_Error using ._ \*  
_Not enough input arguments._

- 
  - 

_Undefined function or variable ‘ddont’._

- 
  - 

_Did you mean:_  
_Undefined function or variable ‘ththere’._

- 
  - 

- \here we go\*
- ↑\*  
_Error: Invalid use of operator._

Thank you all very much in advance !!!

---

<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:** [September 29, 2021, 6:27pm UTC](https://psychtoolbox.discourse.group/t/keyboard-input-mistaken-as-matlab-command/4041/2 "2021-09-29T18:27:21Z")

</div>

You want to suppress keypresses to be sent to matlab, you want them to be captured by ptb only. See ListenChar

Cheers,  
Dee

---

<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:** [September 29, 2021, 7:03pm UTC](https://psychtoolbox.discourse.group/t/keyboard-input-mistaken-as-matlab-command/4041/3 "2021-09-29T19:03:40Z")

</div>

Add `ListenChar(2);` at the beginning of your script, `ListenChar(0);` at the end, and character spilling into the Matlab window will be supressed. If your script error-aborts without calling `ListenChar(0);`, you’ll have to hit CTRL+C twice to get Matlab to recognize keyboard input again. `help ListenChar` for more details.

There’s also the `help Ask` command for another way to do this, instead of GetEchoString, but ListenChar is always needed to suppress character input.

-mario

---

<div class="post-metadata">

**Author:** ![szcody](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@szcody](https://psychtoolbox.discourse.group/u/szcody)\
**Post date:** [September 30, 2021, 12:15am UTC](https://psychtoolbox.discourse.group/t/keyboard-input-mistaken-as-matlab-command/4041/4 "2021-09-30T00:15:59Z")

</div>

> [@mariokleiner](#):
>
> `ListenChar(2);`

Thank you so much !! Should’ve looked up ListenChar first lol.
