C++ 之间的区别键盘键码和 JAVA KeyEvent 键码
我注意到 C++ 中的 vkCode 提供的键码与 Java 的 KeyEvent 提供的键码之间存在差异。 (当然,普通字符具有相同的代码(0 => 48,就像 ASCII 一样),但它们在其他键上有所不同)。 有没有一种方法可以将它们从一个“翻译”到另一个(每个背后的逻辑是什么?)或者我应该为此使用大量开关和IF。 如果有帮助的话,我的应用程序一半使用 C++,一半使用 JAVA,因为 C++ 为我们提供了 Native Hooks,它获取用户按下的按键的键码,然后 java 将使用它们。
提前致谢。
I noticed a difference between the keycodes that vkCode in C++ gives and the ones that Java's KeyEvent gives us. (Ofcourse the normal characters have the same code (0 => 48 just like the ASCII) but they differ in the other keys).
Is there a way to 'translate' them from one to the other (What's the logic behind each one?) or am I supposed to use loads of switches and IFs for that.
If it helps, my app is half in C++ and half in JAVA because of the Native Hooks that c++ gives us and it gets the keycodes of the keys that the user presses and then the java is going to use them.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以将它们放入 查找表,即将Java KeyCode放入一个大数组中,所以只需要做
javaKeyCode = keyLut[cppScanCode]
即可。可以在此处找到一份扫描代码列表,并且
VK_KEYCODES
当然可以在KeyEvent
的 API 文档。Java 被设计为独立于平台,因此例如按左键,无论扫描代码如何,都将始终产生
VK_LEFT
。我不完全确定,但我认为 C++ 扫描代码依赖于硬件。You can probably just put them in a lookup table, that is, put the Java KeyCodes in a large array, so you just need to do
javaKeyCode = keyLut[cppScanCode]
.One list of scan codes can be found here, and the
VK_KEYCODES
can of course be found in the API docs forKeyEvent
.Java is designed to be platform independent, so pressing the left-key for instance, will always yield a
VK_LEFT
, no matter scan code. I'm not entirely sure, but I suppose the C++-scancode is hardware dependent.