[英]How can I use ToUnicode without breaking dead key support?
A similar question has already been asked, so I'm not going to waste time re-explaining it, an existing discussion can be found here: ToAscii/ToUnicode in a keyboard hook destroys dead keys 类似的问题已经被提出,所以我不打算浪费时间重新解释它,现在的讨论可以在这里找到: 键盘钩子中的ToAscii / ToUnicode破坏死键
The reason I'm posting a new question however is that I seem to have come across a 'solution', but I'm not quite sure how to implement it. 我发布一个新问题的原因是我似乎遇到了一个“解决方案”,但我不太确定如何实现它。
This blog post seems to propose a solution to the problem of ToUnicode killing dead-key support: http://www.siao2.com/2005/01/19/355870.aspx 这篇博文似乎提出了ToUnicode杀死死键支持问题的解决方案: http : //www.siao2.com/2005/01/19/355870.aspx
However I'm not sure how to implement the suggested solution. 但是,我不确定如何实施建议的解决方案。 A push in the right direction would be greatly appreciated.
推动正确的方向将非常感激。
To be clear, the part I'm referring to is this: 需要说明的是,我指的是这个:
There are two ways to work around this:
有两种方法可以解决这个问题:
1) You can keep calling ToUnicode with the same info until it is cleared out and then call it one more time to put the state back where it was if you had never typed anything, or
1)您可以继续使用相同的信息调用ToUnicode,直到它被清除,然后再次调用它以将状态恢复到原来的状态,如果您从未输入任何内容,或者
2) You can load all of the keyboard info ahead of time and then when they type information you can look up in your own info cache what the keystrokes mean, without having to call APIs later.
2)您可以提前加载所有键盘信息,然后当他们键入信息时,您可以在自己的信息缓存中查找击键的含义,而无需稍后调用API。
I'm not quite sure how to do either of those things (keyboards and internationalization are far from my strong point), so any help would be greatly appreciated. 我不太确定如何做这些事情(键盘和国际化远非我的强项),所以任何帮助将不胜感激。
Thanks 谢谢
The first part of the answer is entirely information-free. 答案的第一部分完全没有信息。 However, the second part does make sense.
但是,第二部分确实有意义。
ToUnicode()
should have been a pure function, which merely acts as a lookup. ToUnicode()
应该是一个纯函数,它只是作为一个查找。 However, it isn't. 但事实并非如此。 But you can call it repeatedly for all expected inputs, store those in your own lookup table and access that.
但是您可以针对所有预期的输入重复调用它,将它们存储在您自己的查找表中并访问它。
I'd recommend that Microsoft adds a lookDontTouch
flag to the wFlags
parameter; 我建议Microsoft在
wFlags
参数中添加一个lookDontTouch
标志; that would be a trivial non-breaking API fix. 这将是一个简单的非破坏API修复。
If you broaden your search to include key logging , you might get some answers. 如果您扩大搜索范围以包含密钥记录 ,则可能会得到一些答案。 The method presented in the link is extremely cumbersome compared to
ToUnicode
, but it works. 与
ToUnicode
相比,链接中显示的方法非常麻烦,但它有效。 It evolves around finding the current active keyboard layout from the registry and then manually load and parse the proper DLL. 它围绕从注册表中查找当前活动的键盘布局,然后手动加载和解析正确的DLL。
As a note of warning, I've seen the loading part fail miserably on 64-bit Windows. 作为一个警告,我已经看到加载部分在64位Windows上失败了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.