开发者

Difference between C++ Keyboard keycode and JAVA KeyEvent keycode

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 开发者_StackOverflow中文版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.


or am I supposed to use loads of switches and IFs

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 for KeyEvent.

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜