Search in sources :

Example 6 with RawKeyboardAction

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

the class InputSystemTests method releaseKey.

private void releaseKey(Key key) {
    RawKeyboardAction rawKeyboardAction = new RawKeyboardAction(key, ButtonState.UP);
    testKeyboard.add(rawKeyboardAction);
}
Also used : RawKeyboardAction(org.terasology.input.device.RawKeyboardAction)

Example 7 with RawKeyboardAction

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

the class LwjglKeyboardDevice method glfwKeyCallback.

/**
 * Callback receive key input events. All keys in {@link GLFW}
 *
 * @param window window's pointer
 * @param key one of key listed in {@link GLFW} GLFW_KEY*, also you can see {@link
 *         LwjglKeyboardDevice#GLFW_TO_TERA_MAPPING}
 * @param scancode
 * @param action button state now: {@link GLFW#GLFW_PRESS},{@link GLFW#GLFW_RELEASE} or {@link
 *         GLFW#GLFW_REPEAT}
 * @param mods - modification keys: {@link GLFW#GLFW_MOD_SHIFT} and etc.
 */
private void glfwKeyCallback(long window, int key, int scancode, int action, int mods) {
    int teraKey = GLFW_TO_TERA_MAPPING.get(key);
    Input input = InputType.KEY.getInput(teraKey);
    ButtonState state;
    if (action == GLFW.GLFW_PRESS) {
        buttonStates.add(teraKey);
        state = ButtonState.DOWN;
    } else if (action == GLFW.GLFW_RELEASE) {
        state = ButtonState.UP;
        buttonStates.remove(teraKey);
    } else /*if (action == GLFW.GLFW_REPEAT)*/
    {
        state = ButtonState.REPEAT;
    }
    rawKeyQueue.offer(new RawKeyboardAction(input, state));
}
Also used : Input(org.terasology.input.Input) ButtonState(org.terasology.input.ButtonState) RawKeyboardAction(org.terasology.input.device.RawKeyboardAction)

Example 8 with RawKeyboardAction

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

the class InputSystem method simulateSingleKeyStroke.

/**
 * Simulates a single key stroke from the keyboard.
 * <p>
 * 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.
        */
    RawKeyboardAction action = new RawKeyboardAction(key, ButtonState.DOWN);
    simulatedKeys.add(action);
}
Also used : RawKeyboardAction(org.terasology.input.device.RawKeyboardAction)

Example 9 with RawKeyboardAction

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

the class InputSystem method processKeyboardInput.

/**
 * Processes input actions by keyboard buttons, sends key events and updates bind buttons accordingly.
 *
 * @param delta The length of the current frame.
 */
private void processKeyboardInput(float delta) {
    Queue<RawKeyboardAction> keyQueue = keyboard.getInputQueue();
    keyQueue.addAll(simulatedKeys);
    simulatedKeys.clear();
    for (RawKeyboardAction action : keyQueue) {
        boolean consumed = sendKeyEvent(action.getInput(), 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);
        }
    }
    Queue<CharKeyboardAction> charQueue = keyboard.getCharInputQueue();
    charQueue.addAll(simulatedTextInput);
    simulatedTextInput.clear();
    charQueue.forEach((action) -> sendCharEvent(action.getCharacter(), delta));
}
Also used : CharKeyboardAction(org.terasology.input.device.CharKeyboardAction) RawKeyboardAction(org.terasology.input.device.RawKeyboardAction)

Example 10 with RawKeyboardAction

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

the class InputSystem method simulateRepeatedKeyStroke.

/**
 * Simulates a repeated key stroke from the keyboard.
 * <p>
 * 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 simulateRepeatedKeyStroke(Input key) {
    RawKeyboardAction action = new RawKeyboardAction(key, ButtonState.REPEAT);
    simulatedKeys.add(action);
}
Also used : RawKeyboardAction(org.terasology.input.device.RawKeyboardAction)

Aggregations

RawKeyboardAction (org.terasology.input.device.RawKeyboardAction)10 Input (org.terasology.input.Input)2 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 ButtonState (org.terasology.input.ButtonState)1 CharKeyboardAction (org.terasology.input.device.CharKeyboardAction)1