Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Applescript Function Key
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Mark FX" data-source="post: 1557302" data-attributes="member: 211556"><p>You can send keystrokes with Applescript using System Events, but you can't capture keystrokes with it, I've given some examples below.</p><p></p><p>[CODE]</p><p>tell application "System Events"</p><p> keystroke "n" using command down</p><p>end tell</p><p>[/CODE]</p><p>Sends the "n" key to the frontmost app, with command key is down.</p><p></p><p>[CODE]</p><p>tell application "System Events"</p><p> keystroke "Apple" using option down</p><p>end tell</p><p>[/CODE]</p><p>Types the word "Apple" to the frontmost app, with option key down.</p><p></p><p>[CODE]</p><p>tell application "System Events"</p><p> keystroke "n" using {command down, shift down}</p><p>end tell</p><p>[/CODE]</p><p>Sends the "n" key to the frontmost app, with both command and option keys down.</p><p></p><p>The alternative is to use the System Events "key code" commands like this.</p><p></p><p>[CODE]</p><p>tell application "System Events"</p><p> key code 123</p><p>end tell</p><p>[/CODE]</p><p>Sends the left arrow key to the frontmost app.</p><p></p><p>[CODE]</p><p>tell application "TextEdit" to activate</p><p>tell application "System Events"</p><p> keystroke "n" using command down</p><p> keystroke "Apple"</p><p> key code 123</p><p> key code {123, 123, 123} using shift down</p><p> delay (3.0)</p><p> key code 51</p><p>end tell</p><p>[/CODE]</p><p>This script starts TextEdit and starts a new document, then types the word "Apple" into the document, then moves back one character and selects the previous three characters, then pauses for three seconds, then deletes these middle three characters from the word "Apple".</p><p></p><p>So to solve your problem using vanilla Applescript, find out the key codes for the various keys you wish to process, and use as shown above.</p><p>One word of caution though, key code numbers vary based on the keyboard settings and layout, and also may vary with the nationality settings of the keyboard, so the examples above assume a U.S. English (QWERTY) keyboard.</p><p></p><p>Hope this is of some help.</p><p></p><p>Regards Mark</p></blockquote><p></p>
[QUOTE="Mark FX, post: 1557302, member: 211556"] You can send keystrokes with Applescript using System Events, but you can't capture keystrokes with it, I've given some examples below. [CODE] tell application "System Events" keystroke "n" using command down end tell [/CODE] Sends the "n" key to the frontmost app, with command key is down. [CODE] tell application "System Events" keystroke "Apple" using option down end tell [/CODE] Types the word "Apple" to the frontmost app, with option key down. [CODE] tell application "System Events" keystroke "n" using {command down, shift down} end tell [/CODE] Sends the "n" key to the frontmost app, with both command and option keys down. The alternative is to use the System Events "key code" commands like this. [CODE] tell application "System Events" key code 123 end tell [/CODE] Sends the left arrow key to the frontmost app. [CODE] tell application "TextEdit" to activate tell application "System Events" keystroke "n" using command down keystroke "Apple" key code 123 key code {123, 123, 123} using shift down delay (3.0) key code 51 end tell [/CODE] This script starts TextEdit and starts a new document, then types the word "Apple" into the document, then moves back one character and selects the previous three characters, then pauses for three seconds, then deletes these middle three characters from the word "Apple". So to solve your problem using vanilla Applescript, find out the key codes for the various keys you wish to process, and use as shown above. One word of caution though, key code numbers vary based on the keyboard settings and layout, and also may vary with the nationality settings of the keyboard, so the examples above assume a U.S. English (QWERTY) keyboard. Hope this is of some help. Regards Mark [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Applescript Function Key
Top