GetChar and kbwait vs input

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'

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’);

Yay! Thx. I’ll try it tonight.