Looking where those events are created:
In lwjgl 2, they are created by LwjglKeyInput
:
@Override
public void update() {
if (!context.isRenderable())
return;
Keyboard.poll();
while (Keyboard.next()){
int keyCode = Keyboard.getEventKey();
char keyChar = Keyboard.getEventCharacter();
boolean pressed = Keyboard.getEventKeyState();
boolean down = Keyboard.isRepeatEvent();
long time = Keyboard.getEventNanoseconds();
KeyInputEvent evt = new KeyInputEvent(keyCode, keyChar, pressed, down);
evt.setTime(time);
listener.onKeyEvent(evt);
}
}
with lwjgl3 it’s in GlfwKeyInput, creates the events in two callbacks:
private void initCallbacks() {
glfwSetKeyCallback(context.getWindowHandle(), keyCallback = new GLFWKeyCallback() {
@Override
public void invoke(final long window, final int key, final int scancode, final int action, final int mods) {
if (key < 0 || key > GLFW_KEY_LAST) {
return;
}
int jmeKey = GlfwKeyMap.toJmeKeyCode(key);
final KeyInputEvent event = new KeyInputEvent(jmeKey, '\0', GLFW_PRESS == action, GLFW_REPEAT == action);
event.setTime(getInputTimeNanos());
keyInputEvents.add(event);
}
});
glfwSetCharCallback(context.getWindowHandle(), charCallback = new GLFWCharCallback() {
@Override
public void invoke(final long window, final int codepoint) {
final char keyChar = (char) codepoint;
final KeyInputEvent pressed = new KeyInputEvent(KeyInput.KEY_UNKNOWN, keyChar, true, false);
pressed.setTime(getInputTimeNanos());
keyInputEvents.add(pressed);
final KeyInputEvent released = new KeyInputEvent(KeyInput.KEY_UNKNOWN, keyChar, false, false);
released.setTime(getInputTimeNanos());
keyInputEvents.add(released);
}
});
}
both callbacks are called, so three events are created when I press:
new KeyInputEvent(jmeKey, '\0', GLFW_PRESS == action, GLFW_REPEAT == action);
new KeyInputEvent(KeyInput.KEY_UNKNOWN, keyChar, true, false);
new KeyInputEvent(KeyInput.KEY_UNKNOWN, keyChar, false, false);
they match what I saw in the handler.