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