Results 1 to 4 of 4
  1. #1

    Member Since
    Dec 17, 2013
    Applescript Function Key
    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!!

  2. #2

    mrplow's Avatar
    Member Since
    Oct 01, 2007
    27" iMac i7 (2011) 10.11, Mac Mini i5 (2014), iPhone6s, Apple Watch, iPad Air 2, New AppleTV (4?)
    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
    Not been around these parts for a while. Trying to change that . .

    Please use the reputation system if you think you've been helped - bottom left of this post

  3. #3

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    2012 13" MBP (2.5 i5, 8GB)
    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

  4. #4

    Mark FX's Avatar
    Member Since
    Aug 13, 2011
    West Sussex, UK
    You can send keystrokes with Applescript using System Events, but you can't capture keystrokes with it, I've given some examples below.

    tell application "System Events"
        keystroke "n" using command down
    end tell
    Sends the "n" key to the frontmost app, with command key is down.

    tell application "System Events"
        keystroke "Apple" using option down
    end tell
    Types the word "Apple" to the frontmost app, with option key down.

    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.

    tell application "System Events"
        key code 123
    end tell
    Sends the left arrow key to the frontmost app.

    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Assigning a Key a different function
    By Xaver in forum OS X - Operating System
    Replies: 1
    Last Post: 04-28-2015, 08:27 PM
  2. Function key and fn + Delete
    By HansL in forum OS X - Operating System
    Replies: 13
    Last Post: 09-06-2013, 06:41 PM
  3. F12 key function is different
    By edpa777 in forum Switcher Hangout
    Replies: 2
    Last Post: 11-11-2011, 06:29 PM
  4. Function Key
    By JasonBourneOSX in forum Switcher Hangout
    Replies: 3
    Last Post: 06-20-2008, 10:28 PM
  5. Problem with my function key
    By Jhorra in forum Apple Notebooks
    Replies: 4
    Last Post: 02-02-2007, 02:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts