Well, I don’t know where the problem might be. At a first glance the way an input event is being processed looks valid.
Here are the steps:
- The InputSystemJme.java receives a KeyInputEvent and forwards it to Nifty as a KeyboardInputEvent instance (which carries the original character as a Java char - so this should be ok, right?)
[java]private void onKeyEventQueued(KeyInputEvent evt, NiftyInputConsumer nic) {
int code = evt.getKeyCode();
if (code == KeyInput.KEY_LSHIFT || code == KeyInput.KEY_RSHIFT) {
shiftDown = evt.isPressed();
} else if (code == KeyInput.KEY_LCONTROL || code == KeyInput.KEY_RCONTROL) {
ctrlDown = evt.isPressed();
}
KeyboardInputEvent keyEvt = new KeyboardInputEvent(code,
evt.getKeyChar(),
evt.isPressed(),
shiftDown,
ctrlDown);
if (nic.processKeyboardEvent(keyEvt)) {
evt.setConsumed();
}
}
[/java]
- The de.lessvoid.nifty.controls.textfield.TextFieldInputMapping class inside of Nifty will check the de.lessvoid.nifty.input.keyboard.KeyboardInputEvent instance for special keys like cursor up/down etc. since these are treated special inside of Nifty.
So the KeyboardInputEvent is translated inside of Nifty into a NiftyStandardInputEvent enum by the TextFieldInputMapping class. There is a special case enum NiftyStandardInputEvent.Character that is being used if the KeyboardInputEvent contained not one of the special characters but some other “real” character. In that case the character is stored, again as a Java char directly at the enum.
[java] private static NiftyStandardInputEvent handleKeyDownEvent(final KeyboardInputEvent inputEvent) {
switch (inputEvent.getKey()) {
case KeyboardInputEvent.KEY_UP:
return NiftyStandardInputEvent.MoveCursorUp;
case KeyboardInputEvent.KEY_DOWN:
return NiftyStandardInputEvent.MoveCursorDown;
… more code like the above removed for clearity …
default:
break;
}
if (!Character.isISOControl(inputEvent.getCharacter())) {
final NiftyStandardInputEvent character = NiftyStandardInputEvent.Character;
character.setCharacter(inputEvent.getCharacter());
return character;
}
return null;
}
[/java]
- The NiftyInputEvent enum is send to the inputEvent() method of the de.lessvoid.nifty.controls.textfield.Textfield control which processes all of the cursor movements, etc. as well as insert the Character into the textfield String:
[java] public boolean inputEvent(final NiftyInputEvent inputEvent) {
if (inputEvent == null) {
return false;
}
final NiftyStandardInputEvent standardInputEvent = (NiftyStandardInputEvent) inputEvent;
switch (standardInputEvent) {
case MoveCursorLeft:
textField.cursorLeft();
break;
case MoveCursorRight:
textField.cursorRight();
break;
… more code like the above removed for clearity …
case Character:
textField.insert(standardInputEvent.getCharacter());
break;
…
[/java]
So again here the character is treated as a Java char data type. Should be ok.
- In newer versions of Nifty it’s possible to enable filtering of characters at the Textfield level by implementing a de.lessvoid.nifty.controls.textfield.filter.input.TextFieldInputFilter interface
However by default a de.lessvoid.nifty.controls.textfield.filter.input.FilterAcceptAll instance is used which does not filter any characters.
Well, it really would be interesting at which level we’ll lose the chinese characters. Can somebody check this with a debugger or something? I don’t know how to enter chinese characters o_O