diff --git a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyInput.java b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyInput.java index cd87cc70a..e0fa70b92 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyInput.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyInput.java @@ -36,13 +36,21 @@ import com.jme3.input.KeyInput; import com.jme3.input.RawInputListener; import com.jme3.input.event.KeyInputEvent; import com.jme3.system.lwjgl.LwjglWindow; + +import org.lwjgl.glfw.GLFWCharCallback; import org.lwjgl.glfw.GLFWKeyCallback; import java.util.LinkedList; import java.util.Queue; import java.util.logging.Logger; -import static org.lwjgl.glfw.GLFW.*; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_LAST; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE; +import static org.lwjgl.glfw.GLFW.GLFW_PRESS; +import static org.lwjgl.glfw.GLFW.GLFW_REPEAT; +import static org.lwjgl.glfw.GLFW.glfwGetTime; +import static org.lwjgl.glfw.GLFW.glfwSetCharCallback; +import static org.lwjgl.glfw.GLFW.glfwSetKeyCallback; public class GlfwKeyInput implements KeyInput { @@ -52,6 +60,7 @@ public class GlfwKeyInput implements KeyInput { private RawInputListener listener; private boolean initialized; private GLFWKeyCallback keyCallback; + private GLFWCharCallback charCallback; private Queue keyInputEvents = new LinkedList(); public GlfwKeyInput(LwjglWindow context) { @@ -66,14 +75,38 @@ public class GlfwKeyInput implements KeyInput { glfwSetKeyCallback(context.getWindowHandle(), keyCallback = new GLFWKeyCallback() { @Override public void invoke(long window, int key, int scancode, int action, int mods) { + + if (key < 0 || key > GLFW_KEY_LAST) { + return; + } + int jmeKey = GlfwKeyMap.toJmeKeyCode(key); - final KeyInputEvent evt = new KeyInputEvent(jmeKey, (char) key, GLFW_PRESS == action, GLFW_REPEAT == action); - evt.setTime(getInputTimeNanos()); - keyInputEvents.add(evt); + + final KeyInputEvent event = new KeyInputEvent(jmeKey, '\0', GLFW_PRESS == action, GLFW_REPEAT == action); + event.setTime(getInputTimeNanos()); + + keyInputEvents.add(event); } }); - glfwSetInputMode(context.getWindowHandle(), GLFW_STICKY_KEYS, 1); + glfwSetCharCallback(context.getWindowHandle(), charCallback = new GLFWCharCallback() { + + @Override + public void invoke(long window, 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); + } + }); initialized = true; logger.fine("Keyboard created."); @@ -100,6 +133,7 @@ public class GlfwKeyInput implements KeyInput { } keyCallback.release(); + charCallback.release(); logger.fine("Keyboard destroyed."); }