I am using ControllerMate to try to change what my volume buttons do.
Unfortunately, I haven't figured out how I can detect that the F11 or F12 keys are being pressed at the same time as the fn key.
Originally I'd planned to combine an F11 keypress detector and an AppleScript that checks for the fn key.
I haven't been able to find a way in AppleScript to detect the fn key. Research led me to possible solutions, such as
do shell script "/usr/bin/python -c 'import Cocoa; print Cocoa.NSEvent.modifierFlags()'"
But this can't distinguish between the different function keys or fn.
After almost a week trying to figure this out myself I ask you; is there a way to detect in ControllerMate a simultaneous fn and function key press?
Best Answer
I found a way to do this that uses the awesome Karabiner-Elements. This has been so useful for me in many situations, and it works here too.
Karabiner can detect function keys being pressed, and tell whether it's with or without the fn key modifier.
We can make our own "Complex modification" that takes advantage of this:
Complex modifications are stored in
~/.config/karabiner/assets/complex_modifications
as json files. Create a file in here with your favourite text editor:You need to fill the file with your own rules, here's what mine looks like now:
It should be obvious how you can replace the keys with whichever ones you want, and you can also replace the shell command with any shell command.
Add the rule into karabiner-elements by
Starting it up
Choosing "Complex Modifications" from the top
Clicking "(+) Add rule"
Enabling the rule you just defined