I did not take the time to download your code and test it.
I would allow the button press (mainloop?) to run and collect the button press data before the gosub executes and/or write my code to allow the gosub to check for additional buttonpresses by short cycle returns or use interrupts to detect the button press.