Search code examples
applescriptkeystrokekeystrokes

Apple script simulate key events


I want to know the key codes for all the function keys from F1-F12. From previous search queries I have found keycode 107 to turn brightness down by running this

echo "tell application \"System Events\" key code 107 end tell" | osascript

And I'm guessing that simulates the F1 key but the weird thing is 113 turns the brightness up. I haven't been able to find key codes for any other Fn keys. Any help? Is there a nice table made for this where I can get the keycodes. In the end I want to be able to either directly perform the actions that these keys do or somehow simulate those actions. Anything would be fine.


Solution

  • Key code 107 is not the F1 code; it is a separate code for Brightness control. There is also one for Volume control, but it is broken. The key codes are in semi-random order and can not be predicted. The Function keys are:

    F1=122, F2=120, F3=99, F4=118, F5=96, F6=97, F7=98, F8=100, F9=101, F10=109, F11=103, F12=111

    You can find an exhaustive list of Key Codes here.