LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Numknuf on November 19, 2003, 20:32:59

Title: Keyboard mapping
Post by: Numknuf on November 19, 2003, 20:32:59
I noticed that the keys on my norwegian keyboard didn't produce the expected results with lwjgl. When I pressed the plus on the numpad everything is okay, but minus didn't work. Pressing the plus key (not on the numpad) gives the minus. I didn't check any other keys.
Title: Keyboard mapping
Post by: elias on November 20, 2003, 07:47:00
Are we talking key codes or translated keys here? And which OS are you using?

- elias
Title: Keyboard mapping
Post by: Numknuf on November 20, 2003, 08:28:38
This is what I do:

if(Keyboard.isKeyDown(Keyboard.KEY_MINUS))

Pressing a key that resembles '-' doesn't activate this. But pressing the '+' key (situtated where the american '-' is) does the trick.

Tried it with both winxp and w2k.
Title: Keyboard mapping
Post by: elias on November 20, 2003, 08:35:25
That's just it - key codes can change on international keyboards, so you will invariably stumple upon problems like that. If you need the character that appears on the key, you should use keyboard translation. Use

Keyboard.enableBuffering()
Keyboard.enableTranslation()

and read the Keyboard.character after each Keyboard.read().

- elias
Title: Keyboard mapping
Post by: Numknuf on November 20, 2003, 10:13:09
Thanks.

I tried getting the 'int' that the keyboard reports so that I could find out what key lwjgl thinks I'm pressing. Is there a way to get this? (just curios)
Title: Keyboard mapping
Post by: elias on November 20, 2003, 10:15:44
Not sure what you mean by "he 'int' that is reported"? If you mean the raw key code, it is quite OS dependent; every OS has its own virtual key codes.

- elias
Title: Keyboard mapping
Post by: Numknuf on November 20, 2003, 10:27:21
When you do:

if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT))

Your checking the Keyboard.KEY_RIGHT against what the keyboard reported. Is it possible to get the value you're checking against or is this the one that's OS dependent and of no value to me?
Title: Keyboard mapping
Post by: elias on November 20, 2003, 10:31:52
It is OS dependent and of no value to you. The key codes you check against are very raw, and they have no well defined relation to your keyboard and language settings. That's where keyboard translation comes in - it does all the hard work of combining the key code with the keyboard type and language to produce a (unicode) character.

- elias
Title: Keyboard mapping
Post by: Numknuf on November 20, 2003, 10:32:54
Thanks again.