sindresorhus / KeyboardShortcuts

⌨️ Add user-customizable global keyboard shortcuts (hotkeys) to your macOS app in minutes
https://swiftpackageindex.com/sindresorhus/KeyboardShortcuts/documentation/keyboardshortcuts/keyboardshortcuts
MIT License
1.99k stars 185 forks source link

[Answered] Is it possible to capture the eject key on Magic Keyboard A1644? #132

Closed verityj closed 1 year ago

verityj commented 1 year ago

I may not understand how this would work, but throwing a question here, maybe someone would ab able to advise. I work using the magic keyboard A1644 with the eject key on top right. Would I be able to convert it into a forward delete using this or something else that you could recommend? Thank you!

verityj commented 1 year ago

Edit: useless

Just for fun, I created an Automator quick action to run applescript (below) so I could at least test out this concept. I assigned a shortcut to it in System Settings (I chose F5 as the whole point is one key forward delete). It kind of works, but soo slowly (as expected) and each application requires me to enable it under Privacy & SecurityAccessibility before it can access system events. Fun, but pretty much useless and at my limit as a novice here :)

on run {}
    tell application "System Events"
        key code 117
    end tell
end run
sindresorhus commented 1 year ago

It's not supported by this package, but you may be able to do it with https://stackoverflow.com/questions/32499676/capture-osx-media-control-buttons-in-swift

Otherwise, you'll have to use CGEventTap.

This question would be better asked on Stack Overflow though.

verityj commented 1 year ago

In case anyone ever comes across this page looking for information on how to assign any function to the Magic Keyboard Eject key, I want to make sure to say it is easily doable. I found the key binding and wrote about it: https://verityj.github.io/2023/06/17/eject.html

(It bugged me to leave a question unanswered. There was no good info online so it took some time.)