Window close with Escape key or user defined key

Is there is any way to get the keypress event in a window, so that it can close according to the key?.
For example, if the user press esc, it should close.


you may set listener of keydown event of document and close an active item in it:

[code]var active;
dhxAccord.attachEvent(“onActive”, function(id){
active = id;

if (window.addEventListener) {
document.addEventListener(“keydown”, closeActive, false);

} else {
document.attachEvent(“onkeydown”, closeActive);

function closeActive(e){
if ((e||event).keyCode==27)
return true;