Search in sources :

Example 1 with GLFWCharCallback

use of org.lwjgl.glfw.GLFWCharCallback in project jmonkeyengine by jMonkeyEngine.

the class GlfwKeyInput method initialize.

public void initialize() {
    if (!context.isRenderable()) {
        return;
    }
    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 event = new KeyInputEvent(jmeKey, '\0', GLFW_PRESS == action, GLFW_REPEAT == action);
            event.setTime(getInputTimeNanos());
            keyInputEvents.add(event);
        }

        @Override
        public void close() {
            super.close();
        }

        @Override
        public void callback(long args) {
            super.callback(args);
        }
    });
    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);
        }

        @Override
        public void close() {
            super.close();
        }

        @Override
        public void callback(long args) {
            super.callback(args);
        }
    });
    initialized = true;
    logger.fine("Keyboard created.");
}
Also used : GLFWKeyCallback(org.lwjgl.glfw.GLFWKeyCallback) KeyInputEvent(com.jme3.input.event.KeyInputEvent) GLFWCharCallback(org.lwjgl.glfw.GLFWCharCallback)

Aggregations

KeyInputEvent (com.jme3.input.event.KeyInputEvent)1 GLFWCharCallback (org.lwjgl.glfw.GLFWCharCallback)1 GLFWKeyCallback (org.lwjgl.glfw.GLFWKeyCallback)1