In a web app, I am capturing the escape key to exit out of an internal state. I also have support for the app to be embedded in an iframe with controls to make the app full-screen with the fullscreen API (requestFullscreen). Unfortunately, in chrome, the browser uses the escape key to exit out of fullscreen mode. This interferes with my escape key handler.
My first attempt was to try to call preventDefault() on the event. However, after some investigation, it appears that I am not getting the keydown event at all. I do however get other keydown events.
Are there any workarounds to capture the event and prevent the browser from exiting fullscreen mode?
EDIT:
here is what I have now:
$(document).keydown(function(e) {
if( e.keyCode == 27) {
alert('escape was pressed');
//do some stuff
e.preventDefault();
}
});
The alert is never shown.