Search in sources :

Example 1 with KeyEvent

use of com.spinyowl.legui.event.KeyEvent in project legui by SpinyOwl.

the class KeyEventHandler method handle.

@Override
public void handle(SystemKeyEvent event, Frame frame, Context context) {
    int keyCode = event.key;
    KeyboardKey key = new KeyboardKey(Keyboard.getKeyCode(event.key), event.key);
    Component focusedGui = context.getFocusedGui();
    if (focusedGui == null) {
        return;
    }
    KeyAction action = null;
    if (event.action == GLFW_RELEASE) {
        action = KeyAction.RELEASE;
    } else if (event.action == GLFW_PRESS) {
        action = KeyAction.PRESS;
    } else if (event.action == GLFW_REPEAT) {
        action = KeyAction.REPEAT;
    }
    Set<KeyMod> modSet = new HashSet<>();
    if (isMod(event.mods, GLFW_MOD_SHIFT)) {
        modSet.add(KeyMod.SHIFT);
    }
    if (isMod(event.mods, GLFW_MOD_ALT)) {
        modSet.add(KeyMod.ALT);
    }
    if (isMod(event.mods, GLFW_MOD_CONTROL)) {
        modSet.add(KeyMod.CONTROL);
    }
    if (isMod(event.mods, GLFW_MOD_CAPS_LOCK)) {
        modSet.add(KeyMod.CAPS_LOCK);
    }
    if (isMod(event.mods, GLFW_MOD_NUM_LOCK)) {
        modSet.add(KeyMod.NUM_LOCK);
    }
    EventProcessorProvider.getInstance().pushEvent(new KeyEvent(focusedGui, context, frame, event.action, keyCode, event.mods, event.scancode));
    EventProcessorProvider.getInstance().pushEvent(new KeyboardEvent(focusedGui, context, frame, action, key, modSet));
}
Also used : KeyEvent(com.spinyowl.legui.event.KeyEvent) SystemKeyEvent(com.spinyowl.legui.system.event.SystemKeyEvent) KeyMod(com.spinyowl.legui.input.KeyMod) KeyboardEvent(com.spinyowl.legui.event.KeyboardEvent) KeyboardKey(com.spinyowl.legui.input.KeyboardKey) Component(com.spinyowl.legui.component.Component) KeyAction(com.spinyowl.legui.input.KeyAction) HashSet(java.util.HashSet)

Aggregations

Component (com.spinyowl.legui.component.Component)1 KeyEvent (com.spinyowl.legui.event.KeyEvent)1 KeyboardEvent (com.spinyowl.legui.event.KeyboardEvent)1 KeyAction (com.spinyowl.legui.input.KeyAction)1 KeyMod (com.spinyowl.legui.input.KeyMod)1 KeyboardKey (com.spinyowl.legui.input.KeyboardKey)1 SystemKeyEvent (com.spinyowl.legui.system.event.SystemKeyEvent)1 HashSet (java.util.HashSet)1