I have an keyup handler. I want something to happen every time I press ESC except when I’m inside a “Choose File…” window.
Here is a jQuery sample code of what I need:
$(document).bind('keyup', function(e) {
if (e.keyCode == 27) {
if (!IsChooseFileDialogBoxOpen())
doSomething();
}
});
How can I do that?
Thanks
You can’t do that, per-say. But what might be able to do is switch to use the
keydownorkeypressevents instead ofkeyup. Then when the user presses ESC with the file dialog open, thekeydownevent is caught by the dialog and not sent to your JS, so the callback never fires.Check it out here: http://jsfiddle.net/sHKjb/
I tested this in FF, did not do any further testing for Chrome, IE, etc.