Keyboard vs KeyEvent

Thanks to tom’s help, Rimscape is almost ready to have a LWJGL version released. However I’ve come to one odd problem.

When the game is saved, key mappings are recorded since you can set your controls for the game. I do this by saving the key code for each, to be loaded when the settings are loaded.

This is good for one key mapping, but what if someone plays the Java2D version (KeyEvent) and loads his or her game later with LWJGL enabled (Keyboard)? The key codes to not match.

Does anyone have an idea for how I can ensure the appropriate keys are kept bound? If I have to have a switch statement to link all of the keys, how can I ensure I don’t miss any? I’m hoping someone will have an elegant solution for me :wink:

Thanks for any ideas!

I don’t think there is anything to do, but a switch… problem is that lwjgl uses “standard” key bindings, and java uses… “java” key bindings.

You can make sure you don’t miss any, by checking all the constants in Keyboard.java

Yeah, you’re just going to have to maintain a mapping between java keys and LWJGL keys. I expect it’s 1:1 mostly though - never looked…

Cas :slight_smile:

Since Mac OS X is using AWT for keyboard input, I’ve already done most of the mapping (AWT->LWJGL) in org.lwjgl.opengl.KeyboardEventQueue. You can use that for a start.

  • elias

Great! Thanks Elias, I’ll go from there. If I find I need more, I’ll let you know what I’ve developed :slight_smile:

KEY_MAP[KeyEvent.VK_QUOTE] = Keyboard.KEY_APOSTROPHE;

KEY_MAP[KeyEvent.VK_BACK_QUOTE] = Keyboard.KEY_GRAVE;

Those are the only keys I found unbound. I’m not sure if that’s just because Mac’s have it a bit different or something… but yeah, all else looked good to me :slight_smile: However I need it to work differently. For one I need the getMappedKeyCode() method to be public, and I also need a method to go the other way. Would it be ok if I used the pieces of the code from that class in my own little helper class? Do I need to do anything to make that “ok” with the license?

If you include the LWJGL license anyway, it’s ok to take code from it too (My understanding of the BSD license).

  • elias