Search in sources :

Example 6 with KeyInputEvent

use of com.jme3.input.event.KeyInputEvent in project jmonkeyengine by jMonkeyEngine.

the class AwtKeyInput method keyPressed.

public void keyPressed(KeyEvent evt) {
    int code = convertAwtKey(evt.getKeyCode());
    // Check if key was already pressed
    if (!keyStateSet.get(code)) {
        keyStateSet.set(code);
        KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), true, false);
        keyEvent.setTime(evt.getWhen());
        synchronized (eventQueue) {
            eventQueue.add(keyEvent);
        }
    }
}
Also used : KeyInputEvent(com.jme3.input.event.KeyInputEvent)

Example 7 with KeyInputEvent

use of com.jme3.input.event.KeyInputEvent in project jmonkeyengine by jMonkeyEngine.

the class NewtKeyInput method keyPressed.

public void keyPressed(KeyEvent evt) {
    int code = convertNewtKey(evt.getKeySymbol());
    KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), true, evt.isAutoRepeat());
    keyEvent.setTime(evt.getWhen());
    synchronized (eventQueue) {
        eventQueue.add(keyEvent);
    }
}
Also used : KeyInputEvent(com.jme3.input.event.KeyInputEvent)

Example 8 with KeyInputEvent

use of com.jme3.input.event.KeyInputEvent 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)8 GLFWKeyCallback (org.lwjgl.glfw.GLFWKeyCallback)2 TouchEvent (com.jme3.input.event.TouchEvent)1 GLFWCharCallback (org.lwjgl.glfw.GLFWCharCallback)1