Search in sources :

Example 1 with KeyInputEvent

use of com.jme3.input.event.KeyInputEvent 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 KeyInputEvent

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

the class NewtKeyInput method keyReleased.

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

Example 3 with KeyInputEvent

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

the class LwjglKeyInput method update.

public void update() {
    if (!context.isRenderable())
        return;
    Keyboard.poll();
    while (Keyboard.next()) {
        int keyCode = Keyboard.getEventKey();
        char keyChar = Keyboard.getEventCharacter();
        boolean pressed = Keyboard.getEventKeyState();
        boolean down = Keyboard.isRepeatEvent();
        long time = Keyboard.getEventNanoseconds();
        KeyInputEvent evt = new KeyInputEvent(keyCode, keyChar, pressed, down);
        evt.setTime(time);
        listener.onKeyEvent(evt);
    }
}
Also used : KeyInputEvent(com.jme3.input.event.KeyInputEvent)

Example 4 with KeyInputEvent

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

the class AndroidTouchInput method onKey.

public boolean onKey(KeyEvent event) {
    if (!isInitialized()) {
        return false;
    }
    TouchEvent evt;
    // TODO: get touch event from pool
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        evt = new TouchEvent();
        evt.set(TouchEvent.Type.KEY_DOWN);
        evt.setKeyCode(event.getKeyCode());
        evt.setCharacters(event.getCharacters());
        evt.setTime(event.getEventTime());
        // Send the event
        addEvent(evt);
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
        evt = new TouchEvent();
        evt.set(TouchEvent.Type.KEY_UP);
        evt.setKeyCode(event.getKeyCode());
        evt.setCharacters(event.getCharacters());
        evt.setTime(event.getEventTime());
        // Send the event
        addEvent(evt);
    }
    if (isSimulateKeyboard()) {
        KeyInputEvent kie;
        char unicodeChar = (char) event.getUnicodeChar();
        int jmeKeyCode = AndroidKeyMapping.getJmeKey(event.getKeyCode());
        boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN;
        boolean repeating = pressed && event.getRepeatCount() > 0;
        kie = new KeyInputEvent(jmeKeyCode, unicodeChar, pressed, repeating);
        kie.setTime(event.getEventTime());
        addEvent(kie);
    //            logger.log(Level.FINE, "onKey keyCode: {0}, jmeKeyCode: {1}, pressed: {2}, repeating: {3}",
    //                    new Object[]{event.getKeyCode(), jmeKeyCode, pressed, repeating});
    //            logger.log(Level.FINE, "creating KeyInputEvent: {0}", kie);
    }
    //   by the user in MainActivity
    if ((event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) || (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) || (event.getKeyCode() == KeyEvent.KEYCODE_MENU)) {
        return false;
    } else {
        return true;
    }
}
Also used : KeyInputEvent(com.jme3.input.event.KeyInputEvent) TouchEvent(com.jme3.input.event.TouchEvent)

Example 5 with KeyInputEvent

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

the class AwtKeyInput method keyReleased.

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

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