开发者

Converting CGKeyCodes for International Keyboards

In my application, I need to map a shortcut to the key to the left of the "1" key on the keyboard. On a standard US keyboard, this would be the backtick character (" ` "), which is key code number 50. Unfortunately, international keyboards (the French keyboard, for example) has a different key to the left of the 1 key (the forward slash key "/"), so hard coding that key code wou开发者_开发知识库ld result in unexpected results for users who are not using a US keyboard.

Is there any way to convert a US key code into a key code for international keyboards at runtime, or a way to programatically determine the key code based on the position of the key on the keyboard?


The character on the key to the left of "1" is different on different keyboard layouts, but the virtual key code should be the same. If you look at HIToolbox/Events.h, you can see the constant kVK_ANSI_Grave, which represents the key you're talking about; above the list of constants, there's a comment that suggests that at the virtual key code level, equality means that the physical key is the same, though the scan code might be different and the emitted letter might be different.

In other words: the keyboard driver maps from scan codes to virtual key codes, and the keyboard layout (which you can change in System Preferences) maps from virtual key codes to characters.

This is all potentially wrong; I don't have a non-US keyboard with which to verify these assertions.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜