Ah ok, thanks for coming back to me on that. That's really helpful and I really appreciate you making the effort to help me out with this :)
I think that might be linked to how the browser handles the game, rather than the game itself, as the first ESC/Click don't get passed to the game to be handled as javascript inputs. They are consumed by the browser to focus/unfocus the iframe containing the HTML/Javascript version of the game. At least that's my understanding of how it is working, happy to be corrected if I'm wrong there though!