开发者

Pre-define global hotkeys in a cocoa application and the keyboard layout

开发者 https://www.devze.com 2023-03-29 12:35 出处:网络
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'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;

0

精彩评论

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

关注公众号