@Pete you should put an "INKEY" test or something like that to get away from the first loop which has the potential to be a CPU-locking endless loop. Or it might just quit after one iteration so it's worthless...
IDK:
https://qb64phoenix.com/qb64wiki/index.php/WINDOWHANDLE
https://qb64phoenix.com/qb64wiki/index.p...OWHASFOCUS
IDK:
https://qb64phoenix.com/qb64wiki/index.php/WINDOWHANDLE
https://qb64phoenix.com/qb64wiki/index.p...OWHASFOCUS