ExtendScript question: closing script panel if the user press Esc button down
Hi, I have an ExtendScript question. What I'm trying to is close script window if users press ESC key down. Here's my code for it:
dialog.addEventListener('keydown', escExit);
function escExit() {
try {
var myKeyState = ScriptUI.environment.keyboardState;
var pressedString = myKeyState.keyName;
if (myKeyState.keyName == "Escape") {
this.close();
return;
}
}catch (err) {}
}
When I press Esc it closes the window but when I run the script again, sometimes I get this error message. "Unable to execute script at line 5. Execution halted". It refers to "this.close()" line when I change the code "//this.close()" this time it gives an error for the upper line. If I do the same thing for the new line it gives an error for other upper lines. It completely doesn't make any sense to me.
Do you have a better way to do that?