Search in sources :

Example 1 with GLFWKeyCallback

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

the class GlfwKeyInputVR 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) {
            scancode = GlfwKeyMap.toJmeKeyCode(key);
            if (key == GLFW_KEY_LEFT_SHIFT || key == GLFW_KEY_RIGHT_SHIFT) {
                shift_pressed = (action == GLFW_PRESS);
            } else if (key >= 'A' && key <= 'Z' && !shift_pressed) {
                // make lowercase
                key += 32;
            } else if (key >= 'a' && key <= 'z' && shift_pressed) {
                // make uppercase
                key -= 32;
            }
            final KeyInputEvent evt = new KeyInputEvent(scancode, (char) key, GLFW_PRESS == action, GLFW_REPEAT == action);
            evt.setTime(getInputTimeNanos());
            keyInputEvents.add(evt);
        }
    });
    glfwSetInputMode(context.getWindowHandle(), GLFW_STICKY_KEYS, 1);
    initialized = true;
    logger.fine("Keyboard created.");
}
Also used : GLFWKeyCallback(org.lwjgl.glfw.GLFWKeyCallback) KeyInputEvent(com.jme3.input.event.KeyInputEvent)

Example 2 with GLFWKeyCallback

use of org.lwjgl.glfw.GLFWKeyCallback 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)2 GLFWKeyCallback (org.lwjgl.glfw.GLFWKeyCallback)2 GLFWCharCallback (org.lwjgl.glfw.GLFWCharCallback)1