Search in sources :

Example 1 with KeyboardAction

use of org.terasology.input.device.KeyboardAction in project Terasology by MovingBlocks.

the class InputSystem method cancelSimulatedKeyStroke.

public void cancelSimulatedKeyStroke(Input key) {
    char keyChar = key.getDisplayName().charAt(0);
    KeyboardAction action = new KeyboardAction(key, ButtonState.UP, keyChar);
    simulatedKeys.add(action);
}
Also used : KeyboardAction(org.terasology.input.device.KeyboardAction)

Example 2 with KeyboardAction

use of org.terasology.input.device.KeyboardAction in project Terasology by MovingBlocks.

the class LwjglKeyboardDevice method getInputQueue.

@Override
public Queue<KeyboardAction> getInputQueue() {
    Queue<KeyboardAction> result = Queues.newArrayDeque();
    while (Keyboard.next()) {
        ButtonState state;
        if (Keyboard.isRepeatEvent()) {
            state = ButtonState.REPEAT;
        } else {
            state = (Keyboard.getEventKeyState()) ? ButtonState.DOWN : ButtonState.UP;
        }
        Input input = InputType.KEY.getInput(Keyboard.getEventKey());
        result.add(new KeyboardAction(input, state, Keyboard.getEventCharacter()));
    }
    return result;
}
Also used : Input(org.terasology.input.Input) KeyboardAction(org.terasology.input.device.KeyboardAction) ButtonState(org.terasology.input.ButtonState)

Example 3 with KeyboardAction

use of org.terasology.input.device.KeyboardAction in project Terasology by MovingBlocks.

the class InputSystem method simulateSingleKeyStroke.

/**
 * Simulated key strokes: To simulate input from a keyboard, we simply have to extract the Input associated to the action
 * and this function adds it to the keyboard's input queue.
 * @param key The key to be simulated.
 */
public void simulateSingleKeyStroke(Input key) {
    /* TODO: Perhaps there is a better way to extract the character.
            All the simulate functions extract keyChar by getting the first character from it's display string.
            While it works for normal character buttons, might not work for special buttons if required later.
        */
    char keyChar = key.getDisplayName().charAt(0);
    KeyboardAction action = new KeyboardAction(key, ButtonState.DOWN, keyChar);
    simulatedKeys.add(action);
}
Also used : KeyboardAction(org.terasology.input.device.KeyboardAction)

Example 4 with KeyboardAction

use of org.terasology.input.device.KeyboardAction in project Terasology by MovingBlocks.

the class InputSystem method processKeyboardInput.

private void processKeyboardInput(float delta) {
    Queue<KeyboardAction> keyQueue = keyboard.getInputQueue();
    keyQueue.addAll(simulatedKeys);
    simulatedKeys.clear();
    for (KeyboardAction action : keyQueue) {
        boolean consumed = sendKeyEvent(action.getInput(), action.getInputChar(), action.getState(), delta);
        // Update bind
        BindableButton bind = bindsManager.getKeyBinds().get(action.getInput().getId());
        if (bind != null && action.getState() != ButtonState.REPEAT) {
            boolean pressed = action.getState() == ButtonState.DOWN;
            updateBindState(bind, action.getInput(), pressed, delta, consumed);
        }
    }
}
Also used : KeyboardAction(org.terasology.input.device.KeyboardAction)

Example 5 with KeyboardAction

use of org.terasology.input.device.KeyboardAction in project Terasology by MovingBlocks.

the class InputSystem method simulateRepeatedKeyStroke.

public void simulateRepeatedKeyStroke(Input key) {
    char keyChar = key.getDisplayName().charAt(0);
    KeyboardAction action = new KeyboardAction(key, ButtonState.REPEAT, keyChar);
    simulatedKeys.add(action);
}
Also used : KeyboardAction(org.terasology.input.device.KeyboardAction)

Aggregations

KeyboardAction (org.terasology.input.device.KeyboardAction)5 ButtonState (org.terasology.input.ButtonState)1 Input (org.terasology.input.Input)1