Question: How do I make an application that I can make the ESC key close a window? Or really any key (I can change if I want to).

Please help. Thanks

Here is what I have and I can't get it to work.

```
-- close window with "ESC"

tell application "System Events"
    tell application "Finder" to activate
    key code 53

end tell

beep 3

```

Thanks! B-

Answer: 
It's considered better to attach it via JavaScript. This falls under the category of "[Unobtrusive JavaScript](http://en.wikipedia.org/wiki/Unobtrusive_JavaScript)". (more specifically here the separation of behavior from the layout)

```
document.getElementById('YourID').onclick = nameOfFunctionToBeCalled;

```
I use the `ondomready` event to assign all my events, normally squirreled away in a separate script. All my logic is in one place and my markup looks a lot tidier too. I hold the view that markup is merely there to describe the initial structure of the page. Code lives in a code file, and styles belong in a css file.