Keyboard Input Mistaken as MATLAB Command

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

1 Like

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

Cheers,
Dee

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

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