I would suggest you pick one of these threads and use that one for the rest of your questions. It's easier for people to help you if all of your questions are in one place.
I don't think there is a sane way to do this. You could detect 'q' / 'esc', but not the close button in the corner.