1// You can use $.Event() to create an Event object containing a keydown event with the keyCode of 27 (which should be Esc) like:
2
3var esc = $.Event("keydown", { keyCode: 27 });
4$("body").trigger(esc); // change body to the element where you'd like to execute the escape key press.
5