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);
}
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));
}
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);
}
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));
}
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);
}
Aggregations