The keyboard beeping and slowdown may be caused by something else, as the code is performing byte reads (https://qbasic.com/documentation/INP.html) rather than INKEY$ (https://qbasic.com/documentation/INKEY$) or KEY (https://qbasic.com/documentation/KEY). Do you have a suggestion or idea to solve the symptom you are experiencing on your real 8086 PC?
In the meantime, I will look at this page (https://qb64.com/wiki/Scancodes.html) and figure out how to clear the keyboard buffer.
I also was clearing the keyboard buffer in my own entry, there were two methods. I just found something that if I call once per frame after the input read, it mostly works fine even if it might not be the complete solution.
My solution was some interupt call. mov ax,0c00h and then int 21h
However I have some other I didn't use that looks similar to the qbasic solution like here https://www.tek-tips.com/threads/how-do-you-clear-the-input-buffer.77806/
Maybe this one is the easiest to try DEF SEG = &H40: POKE &H1C, PEEK(&H1A): DEF SEG like maybe call it somewhere once in the frame loop after the input checks.
There are also more proper solutions but need more work. In my case I also should have read the input in a continuous loop till the buffer empties. But I just read once and then clear the buffer. Didn't notice issues with keyboard clashing regardless.
Did you btw have the problem yourself or do you run it in Dosbox and you didn't notice the issue?