properly handle the Esc key