how to fire excape key in javascript code example
Example: activate an event on press escape button in jquery
// You can use $.Event() to create an Event object containing a keydown event with the keyCode of 27 (which should be Esc) like:
var esc = $.Event("keydown", { keyCode: 27 });
$("body").trigger(esc); // change body to the element where you'd like to execute the escape key press.