KeyInput.SOME_KEY to string representation of said key?

I’m doing the key binding options in my game and I was wondering if there was a facility to get the visual representation of a KeyInput code.



As it is now, I set some default keys and in my nifty option screen if I want to print in a textfield the keyboard key (not just something like COMMA but the actual “,” character) bound to those configurable actions. Is this possible or do I have to do it all myself?

Not sure what other setup you have so this may not be relevant, but in a raw input listener you get the actual event… and on the event you can get the visual character (for key down messages).

Nothing overly complicated.



Just using an ActionListener, AnalogListener. No Raw input since I don’t really need it. At least not for now.



For now I do:

[java]

Keyboard.getKeyName(gs.getKeyPitchUp())

[/java]



But that returns something like “COMMA” or “RCONTROL”, etc.



I think I’ll stick with that. Less cumbersome than having to parse oddities with foreign languages. I think it’s best that way.

Yup, you’d have to check it while polling the current event: org.lwjgl.input.Keyboard.getEventCharacter().



Otherwise, you could create your own map. http://lwjgl.org/javadoc/org/lwjgl/input/Keyboard.html gets us a listing. You could also, I suppose, create a small app to create the map for you. You just press all the keys on the keyboard and log Keyboard.getEventKey() and Keyboard.getEventCharacter(). I’m not sure, but there may even be away to just programmatically trigger an event for each key so you’re sure not to miss any of them in case your particular keyboard doesn’t have them all… like some laptops don’t have a number pad.



But creating your own little map is probably best. org.lwjgl.input.Keyboard.getKeyName(int key) strips the first 4 characters so you don’t end up with KEY_xxx which is pretty good, so then whichever ones you don’t like, such as “COMMA” you just map from “COMMA” → “,”



Maybe something like this:



[java]



String[] myMap = new String[253];



void initMyMap() {

myMap[Keyboard.KEY_COMMA] = “,”;

myMap[Keyboard.KEY_NUMPAD0] = “0”;

}



String keyToCharacter(int key) {

if(myMap[key] == null) return Keyboard.getKeyName(key); //check this first since we only have a few custom mappings and most of the time we’re just going to get whatever Keyboard would give us like A, B, C…

return myMap[key]; // then if on the rare occasion that it’s something we changed like “COMMA”, we use our value instead “,”

}



[/java]

Thanks for the suggestion but this is a simple key binding method. I feel there’s no reason to jump through multiple hoops for such a simple thing. Besides, I’m imposing myself enough hoop jumping as it is.

Here’s my solution to this problem:

https://github.com/jameskilton/slartibartfast/blob/master/src/org/slartibartfast/events/Keys.java



Mouse and eventually Joystick axes are defined here:

https://github.com/jameskilton/slartibartfast/blob/master/src/org/slartibartfast/events/Axis.java

Thanks @jameskilton I don’t know if I’ll use it or not; just gave it a very quick look, but if I do I’ll let you know.