Ask for Hotkey in Cocoa/Objective-C
I want to have a button which allows the user to pick a global hotkey. I stumbled upon stackoverflow and found some ways to register a hotkey, but none which allows me to let the user pick one. Is there maybe a library for it? Or how you guys handle this?开发者_运维技巧
It should look like this:
If you would like to use an already existing framework, Shortcut Recorder is a good one that is used often. It's pretty easy to use, and might suit your needs. You can also do this manually, as alfred has mentioned, but it's quite a bit more work this way.
You may just create an Event Tap and register keys pressed by the user. When the callback function gets called you'll have enough information to know exactly what keys has been pressed. Then you should just update the string value.
Or, at least, that's the way I'd do it.
精彩评论