Difference between C ++ keyboard code and JAVA KeyEvent keyboard key

I noticed the difference between the key codes that vkCode in C ++ gives and those that the Java KeyEvent gives us. (Of course, normal characters have the same code (0 => 48, like ASCII), but they differ in other keys). Is there a way to “translate” them from one to another (what is the logic of each of them?), Or should I use a lot of switches and IF for this. If this helps, my application is half in C ++ and half in JAVA because of the Native Hooks that C ++ gives us, and it receives the key codes that the user clicks, and then java will use them.

Thanks in advance.

+3
source share
1 answer

or should I use a lot of switches and IFs

Perhaps you can just put them in a lookup table , i.e. put Java KeyCodes in a large array, so you just have to do it javaKeyCode = keyLut[cppScanCode].

One list of scan codes can be found here , but VK_KEYCODESyou can, of course, be found in the docs API forKeyEvent .

Java is designed to be platform independent, so for example, left-clicking will always give VK_LEFT, regardless of the scan code. I'm not quite sure, but I suggest that C ++ - scancode is hardware dependent.

+3
source

Source: https://habr.com/ru/post/1744693/


All Articles