com.jme3.input.event.KeyInputEvent Java Examples

The following examples show how to use com.jme3.input.event.KeyInputEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LwjglKeyInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
    }
}
 
Example #2
Source File: InputSystemJme.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void onKeyEventQueued(KeyInputEvent evt, NiftyInputConsumer nic) {
    int code = evt.getKeyCode();

    if (code == KeyInput.KEY_LSHIFT || code == KeyInput.KEY_RSHIFT) {
        shiftDown = evt.isPressed();
    } else if (code == KeyInput.KEY_LCONTROL || code == KeyInput.KEY_RCONTROL) {
        ctrlDown = evt.isPressed();
    }
    
    KeyboardInputEvent keyEvt = new KeyboardInputEvent(code,
                                                       evt.getKeyChar(),
                                                       evt.isPressed(),
                                                       shiftDown,
                                                       ctrlDown);

    if (nic.processKeyboardEvent(keyEvt)){
        evt.setConsumed();
    }
}
 
Example #3
Source File: InputSystemJme.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void forwardEvents(NiftyInputConsumer nic) {
    int queueSize = inputQueue.size();

    for (int i = 0; i < queueSize; i++){
        InputEvent evt = inputQueue.get(i);
        if (evt instanceof MouseMotionEvent){
            onMouseMotionEventQueued( (MouseMotionEvent)evt, nic);
        }else if (evt instanceof MouseButtonEvent){
            onMouseButtonEventQueued( (MouseButtonEvent)evt, nic);
        }else if (evt instanceof KeyInputEvent){
            onKeyEventQueued( (KeyInputEvent)evt, nic);
        }
    }

    inputQueue.clear();
}
 
Example #4
Source File: IosInputHandler.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void update() {
     logger.log(Level.FINE, "InputEvent update : {0}",
            new Object[]{listener});
   if (listener != null) {
        InputEvent inputEvent;

        while ((inputEvent = inputEventQueue.poll()) != null) {
            if (inputEvent instanceof TouchEvent) {
                listener.onTouchEvent((TouchEvent)inputEvent);
            } else if (inputEvent instanceof MouseButtonEvent) {
                listener.onMouseButtonEvent((MouseButtonEvent)inputEvent);
            } else if (inputEvent instanceof MouseMotionEvent) {
                listener.onMouseMotionEvent((MouseMotionEvent)inputEvent);
            } else if (inputEvent instanceof KeyInputEvent) {
                listener.onKeyEvent((KeyInputEvent)inputEvent);
            }
        }
    }
}
 
Example #5
Source File: AndroidTouchInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void update() {
    if (listener != null) {
        InputEvent inputEvent;

        while ((inputEvent = inputEventQueue.poll()) != null) {
            if (inputEvent instanceof TouchEvent) {
                listener.onTouchEvent((TouchEvent)inputEvent);
            } else if (inputEvent instanceof MouseButtonEvent) {
                listener.onMouseButtonEvent((MouseButtonEvent)inputEvent);
            } else if (inputEvent instanceof MouseMotionEvent) {
                listener.onMouseMotionEvent((MouseMotionEvent)inputEvent);
            } else if (inputEvent instanceof KeyInputEvent) {
                listener.onKeyEvent((KeyInputEvent)inputEvent);
            }
        }
    }
}
 
Example #6
Source File: LwjglKeyInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
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);
    }
}
 
Example #7
Source File: AWTKeyInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void onKeyEvent(KeyEvent keyEvent, boolean pressed) {

        int code = convertKeyCode(keyEvent.getID());
        char keyChar = keyEvent.getKeyChar();

        final KeyInputEvent event = new KeyInputEvent(code, keyChar, pressed, false);
        event.setTime(getInputTimeNanos());

        EXECUTOR.addToExecute(new Runnable() {

          @Override
          public void run() {
            keyInputEvents.add(event);
          }
          
        });
    }
 
Example #8
Source File: TextEntryComponent.java    From Lemur with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onKeyEvent( KeyInputEvent evt ) {
    ModifiedKeyInputEvent mEvt = (ModifiedKeyInputEvent)evt;
    if( mEvt.isPressed() || mEvt.isRepeating() ) {
        KeyAction key = mEvt.toKeyAction(); //new KeyAction(code, (control?KeyAction.CONTROL_DOWN:0), (shift?KeyAction.SHIFT_DOWN:0) );
        KeyActionListener handler = actionMap.get(key);
        if( handler != null ) {
            handler.keyAction(TextEntryComponent.this, key);
            evt.setConsumed();
            return;
        }

        // Making sure that no matter what, certain
        // characters never make it directly to the
        // document
        if( evt.getKeyChar() >= 32 ) {
            model.insert(evt.getKeyChar());
            evt.setConsumed();
            //resetText(); ...should be automatic now
        }
    }
}
 
Example #9
Source File: KeyInterceptState.java    From Lemur with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void dispatch(KeyInputEvent evt) {
    if( !isEnabled() )
        return;
        
    // Intercept for key modifiers
    int code = evt.getKeyCode();
    if( code == KeyInput.KEY_LSHIFT || code == KeyInput.KEY_RSHIFT ) {
        setModifier(KeyModifiers.SHIFT_DOWN, evt.isPressed());
    }
    if( code == KeyInput.KEY_LCONTROL || code == KeyInput.KEY_RCONTROL ) {
        setModifier(KeyModifiers.CONTROL_DOWN, evt.isPressed());
    }        
    if( code == KeyInput.KEY_LMENU || code == KeyInput.KEY_RMENU ) {
        setModifier(KeyModifiers.ALT_DOWN, evt.isPressed());
    }        
        
    ModifiedKeyInputEvent wrapper = null;
    for( KeyListener l : keyListeners.getArray() ) {
        // Only wrap if we will actually deliver
        if( wrapper == null ) {
            wrapper = new ModifiedKeyInputEvent(evt, modifiers);
        }
        l.onKeyEvent(wrapper);
    }
}
 
Example #10
Source File: TestBitmapFont.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onKeyEvent(KeyInputEvent evt) {
    if (evt.isReleased())
        return;
    if (evt.getKeyChar() == '\n' || evt.getKeyChar() == '\r') {
        txt3.setText(str.toString());
        str.setLength(0);
    } else {
        str.append(evt.getKeyChar());
    }
}
 
Example #11
Source File: AbstractCameraController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onKeyEvent(KeyInputEvent kie) {
    if (kie.isPressed()) {
        if (KeyInput.KEY_LSHIFT == kie.getKeyCode()) {
            shiftModifier = true;
        }
    } else if (kie.isReleased()) {
        if (KeyInput.KEY_LSHIFT == kie.getKeyCode()) {
            shiftModifier = false;
        }
    }
}
 
Example #12
Source File: AwtKeyInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void keyReleased(KeyEvent evt) {
    int code = convertAwtKey(evt.getKeyCode());
    KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), false, false);
    keyEvent.setTime(evt.getWhen());
    synchronized (eventQueue){
        eventQueue.add(keyEvent);
    }
}
 
Example #13
Source File: InputManager.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void onKeyEventQueued(KeyInputEvent evt) {
    if (evt.isRepeating()) {
        return; // repeat events not used for bindings
    }
    
    int hash = KeyTrigger.keyHash(evt.getKeyCode());
    invokeActions(hash, evt.isPressed());
    invokeTimedActions(hash, evt.getTime(), evt.isPressed());
}
 
Example #14
Source File: AwtKeyInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void keyPressed(KeyEvent evt) {
    int code = convertAwtKey(evt.getKeyCode());
    KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), true, false);
    keyEvent.setTime(evt.getWhen());
    synchronized (eventQueue){
        eventQueue.add(keyEvent);
    }
}
 
Example #15
Source File: InputManager.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Callback from RawInputListener. Do not use.
 */
public void onKeyEvent(KeyInputEvent evt) {
    if (!eventsPermitted) {
        throw new UnsupportedOperationException("KeyInput has raised an event at an illegal time.");
    }

    inputQueue.add(evt);
}
 
Example #16
Source File: ComposerCameraController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onKeyEvent(KeyInputEvent kie) {
    //don't forget the super call
    super.onKeyEvent(kie);
    if (kie.isPressed()) {
        if (KeyInput.KEY_LSHIFT == kie.getKeyCode()) {
            forceCameraControls = true;
        }
    } else if (kie.isReleased()) {
        if (KeyInput.KEY_LSHIFT == kie.getKeyCode()) {
            forceCameraControls = false;
        }
    }
}
 
Example #17
Source File: TerrainCameraController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onKeyEvent(KeyInputEvent kie) {
    super.onKeyEvent(kie);
    if (kie.isPressed()) {
        if (KeyInput.KEY_LSHIFT == kie.getKeyCode()) {
            forceCameraControls = true;
        }
    } else if (kie.isReleased()) {
        if (KeyInput.KEY_LSHIFT == kie.getKeyCode()) {
            forceCameraControls = false;
        }
    }
}
 
Example #18
Source File: GlfwKeyInputVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
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 ) {
                key += 32; // make lowercase
            } else if( key >= 'a' && key <= 'z' && shift_pressed ) {
                key -= 32; // make uppercase
            }
            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.");
}
 
Example #19
Source File: AwtKeyInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
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);
        }                        
    }
}
 
Example #20
Source File: AwtKeyInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
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);
        }            
    }
}
 
Example #21
Source File: InputSystemJme.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void onKeyEvent(KeyInputEvent evt) {
    inputQueue.add(evt);
}
 
Example #22
Source File: TestJoystick.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onKeyEvent(KeyInputEvent evt) {}
 
Example #23
Source File: AWTKeyInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public AWTKeyInput(AWTContext context) {
    super(context);
    keyInputEvents = new LinkedList<KeyInputEvent>();
}
 
Example #24
Source File: TestSoftwareMouse.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void onKeyEvent(KeyInputEvent evt) {
}
 
Example #25
Source File: NiftyJmeDisplay.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void simulateKeyEvent( KeyInputEvent event ) {
    inputSys.onKeyEvent(event);
}
 
Example #26
Source File: ModifiedKeyInputEvent.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public ModifiedKeyInputEvent( KeyInputEvent delegate, int modifiers ) {
    super(delegate.getKeyCode(), delegate.getKeyChar(), 
          delegate.isPressed(), delegate.isRepeating());
    this.delegate = delegate;
    this.modifiers = modifiers;                  
}
 
Example #27
Source File: DefaultRawInputListener.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void onKeyEvent( KeyInputEvent evt ) {
}
 
Example #28
Source File: KeyInterceptState.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onKeyEvent( KeyInputEvent evt ) {
    dispatch(evt);
}
 
Example #29
Source File: RawInputListener.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Invoked on keyboard key press or release events.
 * 
 * @param evt 
 */
public void onKeyEvent(KeyInputEvent evt);
 
Example #30
Source File: KeyListener.java    From Lemur with BSD 3-Clause "New" or "Revised" License votes vote down vote up
public void onKeyEvent( KeyInputEvent evt );