esc key

I want to have applescript emulate the esc key being pressed. I have tried

keystroke {esc}

No Luck.

Posted on Oct 28, 2005 10:44 AM

Reply
7 replies

Oct 29, 2005 11:12 AM in response to George Ryon

I would stick to the ascii key code. It seems to me that they work better most of the time. So the syntax to emulate the press is:

tell application "System Events"
tell process "the process you want to effect"
keystroke (ASCII character 27)
end tell
end tell

Also, you have to make sure that support for assistive devices is enabled. You can do this by going to System Preferences-->Universal Access-->Enable Access for Assistive Devices. Finally, if the command is part of a larger script, you may need to insert some delays after or before the keystroke to allow the application to react. Good Luck!

Dec 11, 2005 9:50 AM in response to Richard Henry

I don't think there is an AppleScript command to wait for a specific key down event and capture it. The usual way to delay a script if you want to do something else (like switch to another application to do something) is to use a display dialog. While the dialog is up, the script stops, when it is dismissed by clicking a button or pressing "Enter" for a default button, the script continues.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

esc key

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.