# GetChar and kbwait vs input

**URL:** <https://psychtoolbox.discourse.group/t/getchar-and-kbwait-vs-input/3213>\
**Category:** Bugs & Features\
**Tags:** macos\
**Created:** [May 10, 2020, 8:25am UTC](https://psychtoolbox.discourse.group/t/getchar-and-kbwait-vs-input/3213 "2020-05-10T08:25:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![denis.pelli](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/denis.pelli/32/7_2.png) [@denis.pelli](https://psychtoolbox.discourse.group/u/denis.pelli)\
**Post date:** [May 10, 2020, 8:25am UTC](https://psychtoolbox.discourse.group/t/getchar-and-kbwait-vs-input/3213/1 "2020-05-10T08:25:18Z")

</div>

The MATLAB “input” command does not operate properly after I’ve called either kbwait or GetChar.  
The program below is supposed to ask the user to hit RETURN six times. But lines 2 and 5 are  
both immediately followed by the next lines, without waiting for a keypress. So the user in fact only types RETURN four times, despite six prompts. The commented lines  
are my attempts to fix this, but they don’t help. Why can’t I mix “input” with either “kbwait” or “GetChar”?  
I’m baffled. Can someone tell me what’s going on or make this work?  
Best  
Denis

input(‘1. Hit RETURN to continue.’,‘s’);  
fprintf(‘2. Hit RETURN to continue.’);  
% FlushEvents;  
% while CharAvail  
% GetChar;  
% end  
GetChar;  
% while CharAvail  
% GetChar;  
% end  
input(‘3. Hit RETURN to continue.’,‘s’);  
input(‘4. Hit RETURN to continue.’,‘s’);  
fprintf(‘5. Hit RETURN to continue.\n’);  
FlushEvents  
KbWait;  
FlushEvents;  
input(‘6. Hit RETURN to continue.’,‘s’);

```
                  model: 'MacBookPro14,3'
        modelDescription: 'MacBook Pro (15-inch, 2017)'
            manufacturer: 'Apple Inc.'
            psychtoolbox: 'Psychtoolbox 3.0.16'
                  matlab: 'MATLAB 9.6 (R2019a)'
                  system: 'macOS 10.14.6'
               screenMex: 'Screen.mexmaci64 Mar 4 2020'
                 screens: 0
                  screen: {[0]}
                    size: {[3360 2100]}
              nativeSize: {[3360 2100]}
                      mm: {[330 206]}
          openGLRenderer: {'AMD Radeon Pro 560 OpenGL Engine'}
            openGLVendor: {'ATI Technologies Inc.'}
           openGLVersion: {'2.1 ATI-2.11.21'}
psychtoolboxKernelDriver: 'PsychtoolboxKernelDriver 1.1'
          drawTextPlugin: 1
          psychPortAudio: 1
                 summary: 'MacBookPro14,3-macOS-10.14.6-PTB-3.0.16'
```

---

<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:** [May 10, 2020, 6:57pm UTC](https://psychtoolbox.discourse.group/t/getchar-and-kbwait-vs-input/3213/2 "2020-05-10T18:57:37Z")

</div>

All keystrokes recorded by GetChar() and detected by KbCheck etc. also go to Matlab, unless properly suppressed via ListenChar(). Nothing new here over the last 15 years.

This works, as it should:

input(‘1. Hit RETURN to continue.’,‘s’);  
fprintf(‘2. Hit RETURN to continue.\n’);  
ListenChar(2);  
GetChar;  
FlushEvents;  
ListenChar(0);  
input(‘3. Hit RETURN to continue.’,‘s’);  
input(‘4. Hit RETURN to continue.’,‘s’);  
fprintf(‘5. Hit RETURN to continue.\n’);  
ListenChar(-1);  
KbStrokeWait;  
ListenChar(0);  
input(‘6. Hit RETURN to continue.’,‘s’);

---

<div class="post-metadata">

**Author:** ![denis.pelli](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/denis.pelli/32/7_2.png) [@denis.pelli](https://psychtoolbox.discourse.group/u/denis.pelli)\
**Post date:** [May 10, 2020, 8:07pm UTC](https://psychtoolbox.discourse.group/t/getchar-and-kbwait-vs-input/3213/3 "2020-05-10T20:07:29Z")

</div>

Yay! Thx. I’ll try it tonight.
