New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Applescript Function Key


Post Reply New Thread Subscribe

 
Thread Tools
hypergreenbean

 
Member Since: Dec 17, 2013
Posts: 1
hypergreenbean is on a distinguished road

hypergreenbean is offline
Hello everyone,

I'm not exactly sure which sub-forum to put this in so I hope this is okay.

I was curious how I could program my mac to keystroke Fn+F8. I know that F8 is key code 100 but I can't figure out how to get the script to also press Fn.

I'm trying to make a script that sends this keystroke so that I can use Quicksilver to activate this script when I press option+j. Essentially, I'm trying to Pause/Play VLC by pressing option+J.

Thanks so much in advance!!
QUOTE Thanks
mrplow

 
mrplow's Avatar
 
Member Since: Oct 01, 2007
Location: UK
Posts: 6,728
mrplow has a reputation beyond reputemrplow has a reputation beyond reputemrplow has a reputation beyond reputemrplow has a reputation beyond reputemrplow has a reputation beyond reputemrplow has a reputation beyond reputemrplow has a reputation beyond reputemrplow has a reputation beyond reputemrplow has a reputation beyond reputemrplow has a reputation beyond reputemrplow has a reputation beyond repute
Mac Specs: 27" iMac i7 (2011) 10.9, iPhone5s, iPad Air, AppleTV2

mrplow is offline
Fastscripts lets you assign function keys to Applescripts

Although your example of VLC seems strange to me as it already has it's own keyboard shortcuts.

You can just tap the space bar for Play/Pause for example

External hard disk acquisition addict - but admitting the problem is the first step to a robust backup

Please use the reputation system if you think you've been helped - top right of this post
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 17,815
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is online now
If your scripting key combinations frequently and need to get codes, maybe a little app like "Key Codes" on the App Store will help. That said, I just tried it and get 100 for Fn-F8. You shouldn't need to push function though - the play/pause button should work as normal in VLC.

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks
Mark FX

 
Mark FX's Avatar
 
Member Since: Aug 13, 2011
Location: West Sussex, UK
Posts: 168
Mark FX has a spectacular aura about

Mark FX is offline
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
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
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
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
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
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 Thanks

Post Reply New Thread Subscribe


« Bash command not found | Fullscreen using NSApplication setPresentationOptions. »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Set a function key to turn on mirroring for my iMac fleurya OS X - Operating System 1 10-24-2012 11:17 PM
Help With SSH Private Key gaspower OS X - Operating System 1 06-02-2011 06:15 PM
Missing Key on UK PowerBook 12 inch Aluminium rudeboymick Apple Notebooks 1 06-08-2008 08:51 PM
Problem with my function key Jhorra Apple Notebooks 4 02-02-2007 01:17 PM
Weirdly Locked Key Combos when Using USB Apple Pro Keyboard dorisdanglehoff Apple Notebooks 0 11-09-2006 08:09 PM

All times are GMT -4. The time now is 05:54 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?