handle close event and keyboard::escape