开发者

best way to store an hotkey in preferences

开发者 https://www.devze.com 2023-01-25 15:04 出处:网络
I am wondering about the best way to store a hotkey in preferen开发者_运维知识库ces in a Coco application.A hotkey is really just a keyCode+modifierFlags pair that point to some chunk of code to execu

I am wondering about the best way to store a hotkey in preferen开发者_运维知识库ces in a Coco application.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消