Java Code Examples for com.jme3.input.event.KeyInputEvent#getKeyCode()

The following examples show how to use com.jme3.input.event.KeyInputEvent#getKeyCode() . 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: 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 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: 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 4
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 5
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 6
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;                  
}