Can Applescript "listen" for a certian key being pressed?

I have a loop script running that repeats a certian task at a specific interval. I want the user to be able to halt the script by pressing the escape key. I cant seem to find anyway to detect that key being pressed. Any help would be greatly appreciated!!

Use Jon’s Commands scripting addition ‘keys pressed’:

http://www.seanet.com/~jonpugh/

Here’s an example:

repeat
	beep 1
	if (keys pressed) contains "Escape" then exit repeat
	do shell script "sleep 1"
end repeat

Acommon mistake is to use an infinite repeat loop without a break. If you do that, then the script will have a hard time detecting user input. That’s what the delay is for. Otherwise you might use an idle handler.

gl,

Thanks Kel, I’ll try that. I’ve had trouble getting Jon’s Commands working properly in the past but I will try again.