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