• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sending Key Commands?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sending Key Commands?


  • Subject: Re: Sending Key Commands?
  • From: Alex Hall <email@hidden>
  • Date: Sat, 11 Oct 2014 14:58:46 -0400

Thank you everyone, I think I have it working now. Plus, I'll know what to look up in the future, now that I know the mechanism for doing this.
On Oct 11, 2014, at 12:38 PM, Bill Cheeseman <email@hidden> wrote:

Scripting the function keys is much trickier, for several reasons. I won't try to list them all here. For example, how you set the "Use all F1, F2, etc. keys as standard function keys" setting in the Keyboard pane of Keyboard preferences in System Preferences makes a big difference. Personally, I always have that setting turned on, meaning that I have to hold down the fn key to use the system functions printed on the function keys. But even then some function keys perform fixed system functions even without holding down the fn key and can't be scripted (for example, F12 opens Dashboard), unless you change those function key assignments in the Shortcuts pane of Keyboard preferences.

That said, the basic idea is to use the System Events 'key code' command. The following script will open Adobe Community Help, because Adobe Reader uses F1 as a keyboard shortcut to open Help.

activate application "Adobe Reader"
tell application "System Events"
key code 122 -- F1 key
end tell

You can look up the key codes on the Web, or you can use any of several utilities that give you the key code for any key you press -- for example, the cleverly named Key Codes application on the Mac App Store. Or you can buy my UI Browser application, which includes a key code lookup drawer and an AppleScript generator that generates 'keystroke' and 'key code' statements, and which includes many other features useful for GUI Scripting in general. <http://pfiddlesoft.com/uibrowser> My recollection is that these key codes may differ on different Mac keyboards and keyboard layouts, but it has been a very, very long time since I read that chapter of Inside Macintosh (although I still have it here on my bookcase, hmm, let's see...).

On Oct 11, 2014, at 10:58 AM, Alex Hall <email@hidden> wrote:

My only other question is: how do I send F keys? If I use "F5", only the F appears to be sent.

-- 

Bill Cheeseman - email@hidden

--
Have a great day,
Alex Hall
email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Sending Key Commands? (From: Alex Hall <email@hidden>)
 >Re: Sending Key Commands? (From: Bill Cheeseman <email@hidden>)
 >Re: Sending Key Commands? (From: Alex Hall <email@hidden>)
 >Re: Sending Key Commands? (From: Bill Cheeseman <email@hidden>)
 >Re: Sending Key Commands? (From: Alex Hall <email@hidden>)
 >Re: Sending Key Commands? (From: Bill Cheeseman <email@hidden>)

  • Prev by Date: Contacts Plugin AppleScript
  • Next by Date: Bug with "attribute run" and Safari ?
  • Previous by thread: Re: Sending Key Commands?
  • Next by thread: Contacts Plugin AppleScript
  • Index(es):
    • Date
    • Thread