如何将VK扫描代码转换为所选语言的适当字符 [英] How to convert VK scan codes to appropriate character for language selected
问题描述
我有一个多语言应用程序,我必须将VK扫描代码转换为当前键盘布局所指定的适当字符,前提是它们已映射到某些字符表示形式,而不仅是动作,状态或其他元数据.使用.我将如何做到这一点,以便它可以使用不同的语言在不同的Windows上移植?
I have an application which is multilingual, and I have to convert the VK scan codes to the appropriate character as specified by the current keyboard layout provided that they are mapped to some character representation and not just an action, state or other meta use. How would I accomplish this, such that it is portable across different Windows using different languages?
我可以为VK扫描代码编写一个映射函数,但是在WinUser.h
文件中,我正在读取诸如以下内容:
I could write a mapping function for the VK scan codes, but in the WinUser.h
file, I'm reading stuff like:
#define VK_OEM_4 0xDB // '[{' for US
#define VK_OEM_5 0xDC // '\|' for US
#define VK_OEM_6 0xDD // ']}' for US
#define VK_OEM_7 0xDE // ''"' for US
这表示如果键盘不是美式,则可能有所不同.必须有一个可以调用的函数,它可以通过键盘驱动程序或类似的东西进行适当的映射,对吗?
Which indicates that if the keyboard isn't US, this could be different. There must be a function that I can call to do the appropriate mapping through the keyboard driver or something, right?
推荐答案
可靠的解决方案是处理WM_CHAR
消息.将字符输入与击键分开可为您提供映射,不仅支持内置Windows键盘布局,还支持IME,语音API,手写输入和其他第三方输入方法. MapVirtualKey
,ToUnicode
和相关功能依赖于Windows内核中有关死键的内部状态,因此不能保证总是返回正确的字符.
The reliable solution is to process WM_CHAR
messages. Separating character input from keystrokes provide the mapping for you, and supports not only built-in Windows keyboard layouts but also IMEs, speech APIs, handwriting and other third party input methods. MapVirtualKey
, ToUnicode
and related functions rely on internal state in the Windows kernel with respect to deadkeys and so cannot be guaranteed to always return the correct character(s).
这篇关于如何将VK扫描代码转换为所选语言的适当字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!