Have you looked at the help area for the keyword INTERRUPT? I see there is a provision for it. I've never used it.
Are you a commodore 64 user? The C64 has one, the restore key. It does just what you're asking.
CHR$(27) is Escape. Hmm?
One thing to note: Some commands take *total* control of your program and *can not* be easily interrupted. From the top of my head, if I’m remembering correctly, INPUT is one of them. If you need a program to be response to various key/mouse states, at all times, be certain to never use INPUT in that program. Use INKEY$, _KEYHIT, _DEVICE, INP, or some other method to get input from the program.
INPUT itself takes total control and waits for that valid ENTER press before it releases control and resumes normal program operation.