How to convert VK scan codes to appropriate character for language selected

有些话、适合烂在心里 提交于 2019-12-10 11:42:10

问题


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?

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?


回答1:


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).



来源:https://stackoverflow.com/questions/30741730/how-to-convert-vk-scan-codes-to-appropriate-character-for-language-selected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!