Reputation: 5323
I am wondering about the best way to store a hotkey in preferences in a Coco application.
Upvotes: 2
Views: 166
Reputation: 243156
A hotkey is really just a keyCode+modifierFlags pair that point to some chunk of code to execute. So I'd probably do something like:
[[NSUserDefaults standardUserDefaults] setInteger:myHotKeyKeyCode forKey:@"HotKeyKeyCode"];
[[NSUserDefaults standardUserDefaults] setInteger:myHotKeyModifierFlags forKey:@"HotKeyModifierFlags"];
Then when your app launches again....
NSInteger keyCode = [[NSUserDefaults standardUserDefaults] integerForKey:@"HotKeyKeyCode"];
NSInteger modifierFlags = [[NSUserDefaults standardUserDefaults] integerForKey:@"HotKeyModifierFlags"];
//register the keyCode and modifierFlags to execute some chunk of code
Upvotes: 2