Is there some easy way to stop code that is currently being executed if certain keys are pressed (put an if statement in form_keypress)?

I would like to stop some things from happening if certain keys are pressed.

I'm not sure how to do this... say you have a sub that you call and it has code (and triggered events) in it that takes 30 seconds to execute. Well how could you stop and exit this sub using code in form_keypress?

Thanks so much for anyone's help. I'm quite puzzled at the moment.