views:

262

answers:

1

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.

+1  A: 

or am I supposed to use loads of switches and IFs

You can probably just put them in a look-up-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.

aioobe
Thanks. I think this is my only hope. I havn't actually used the Lut before and the Netbeans IDE is telling me It's from the Java.Awt.Image. Is that the right one?
Auxiliary
No no, lookup tables has nothing to do with the api. It's simply a way of encoding simple functions in as arrays.
aioobe