Need to tell application to close window on certain keystroke

Hello All:

I am new to applescript and figured this was my best option for now for what I want to do.

I want to be able to close the open IM window in adium when I press the esc key however I am not sure how to do it. This is what I have so far:

tell application “Adium”
activate
keystroke " "
close window 1
end tell

This did not work, needless to say, mainly cause I don’t know how to say escape inside the quotes.

Any help or advice on this would help me out a lot.

Thanks

ok, it only took me 3hrs to figure out but I got this script to work…

tell application “System Events”
keystroke escape key
tell application “Adium” to close chat window 1

end tell

however, I need this to work when I press the escape key. Can someone help or point me in a direction so I can save this or get this to work with my IM chat.

I have also tried this snip here

tell application “System Events”
tell application “Adium” to close chat window 1
key code 53
end tell

thanks,

Paul