Pre-define global hotkeys in a cocoa application and the keyboard layout
I'd love to pre-define some global hotkeys in my little cocoa application, and my question is: should I worry about the keyboard layouts?
I mean for example, when I pre-define a global key combo like "Cmd+Opt+A", I can look up key code of 'A' and hard-code it in my program, but i'm not sure if it would be a problem when users using a different keyboard layout rather than mine. Aslo, is it OK to use kVK_ANSI_A etc in this situation? What's the best practice to handle this kind of prob开发者_开发知识库lem?
Thanks!
Keycodes are designed to be universally. That is why they are used rather than just the letter "A". So yeah, it is safe to do so. Here is a very useful app on the mac app store for finding key codes. They keycode for "A" is 97. So you can register a hotkey using keycode = 97
and modifierFlags = NSCommandKeyMask | NSAlternateKeyMask;
精彩评论