Easy fix for this issue:
1) Go into internal/c/ and open libqb.cpp.
2) Search for "void sub_sleep(int32 seconds,int32 passed){" -- this is where our c-code for the SLEEP command is located.
3) Scroll down just a few lines (it's line 15,308 for me, but those line numbers change with each edit of the source).
Look for: do{ //ignore all console input
junk=func__getconsoleinput();
junk2=consolekey;
}while(junk!=1); //until we have a key down event
This segment is the problem, as it's too vague for what it considers a proper "key down" event. When we press any key in the console, we generate TWO key events -- one for "key down" and one for "key up". By using the PAUSE statement via SHELL, we clear the "key down" event and then the SLEEP command reads the "key up" as our key event -- which is why it's then trapped waiting for us to press that same key back down once again.
The change here is rather simple -- replace that code segment with the following: do{ //ignore all console input unless it's a keydown event
do{ //ignore all console input unless it's a keyboard event
junk=func__getconsoleinput();
junk2=consolekey;
}while(junk!=1); //only when junk = 1 do we have a keyboard event
}while(junk2<=0); //only when junk2 > 0 do we have a key down event. (values less than 0 are key up events; 0 is a non event)
The above says, "Let's ignore any key up events, and only work with SLEEP with a keydown event." (junk2 is the actual keypress, whereas junk is the *source* of the keypress -- in this case, it needs to be 1 to be the keyboard and not the mouse or some other console input event).
4) Once you've made that edit, save libqb.cpp.
5) Close libqb.cpp.
6) Inside the internal/c/ folder (the same one where you found libqb.cpp, you'll see a batch file called "purge_libqb_only.bat".
7) Run that batch file to remove the old library file. Don't worry. QB64 will rebuild it automatically for you.
At this point, you can now open QB64.exe, paste in your test program, and have it run as you'd expect.
A simple glitch, and simple to correct. Many thanks for helping to locate this one for me. It's one of those little things that's easy to overlook, until people start actually testing the code and find the issue for you. I don't use the console enough to usually catch any of these small problems, so it's much appreciated when someone does and then takes time to point them out as eloquently as you did. The second example of yours really helped highlight to issue for me, so I could zoom in on the problem and correct it quickly. :)
EDIT: A minor change to make certain it works as intended and doesn't respond to other external non-keyboard events.