diff --git a/src/main/java/com/mattsmeets/macrokey/handler/hook/KeyInputHandler.java b/src/main/java/com/mattsmeets/macrokey/handler/hook/KeyInputHandler.java index bfd1787..a024bc9 100644 --- a/src/main/java/com/mattsmeets/macrokey/handler/hook/KeyInputHandler.java +++ b/src/main/java/com/mattsmeets/macrokey/handler/hook/KeyInputHandler.java @@ -28,11 +28,26 @@ public KeyInputHandler(final BindingsRepository bindingsRepository, final ModSta } @SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true) - public void onKeyInputEvent(InputEvent.KeyInputEvent event) throws IOException { - final int keyCode = event.getKey(); - final boolean keyIsDown = event.getAction() == GLFW.GLFW_PRESS; + public void onKeyInputEvent(InputEvent event) throws IOException { + int keyCode = -1; + boolean keyIsDown = false; + int interfaceType = 0; + int modifier = 0; + if(!(event instanceof InputEvent.KeyInputEvent || event instanceof InputEvent.RawMouseEvent)) { + return; + } + if(event instanceof InputEvent.KeyInputEvent) { + keyCode = ((InputEvent.KeyInputEvent) event).getKey(); + keyIsDown = ((InputEvent.KeyInputEvent) event).getAction() == GLFW.GLFW_PRESS; + modifier = ((InputEvent.KeyInputEvent) event).getModifiers(); + } else { + keyCode = ((InputEvent.RawMouseEvent) event).getButton(); + keyIsDown = ((InputEvent.RawMouseEvent) event).getAction() == GLFW.GLFW_PRESS; + modifier = ((InputEvent.RawMouseEvent) event).getMods(); + interfaceType = 1; + } - final Set macroList = bindingsRepository.findMacroByKeyCode(keyCode, modState.getActiveLayer(), false); + final Set macroList = bindingsRepository.findMacroByKeyCode(keyCode, interfaceType, modifier, modState.getActiveLayer(), false); if (macroList.isEmpty()) { return; } diff --git a/src/main/java/com/mattsmeets/macrokey/model/Macro.java b/src/main/java/com/mattsmeets/macrokey/model/Macro.java index f095fdc..fca7d7a 100644 --- a/src/main/java/com/mattsmeets/macrokey/model/Macro.java +++ b/src/main/java/com/mattsmeets/macrokey/model/Macro.java @@ -15,6 +15,12 @@ public class Macro implements MacroInterface { */ private UUID umid; + // 0 = keyboard, 1 = mouse + private int interfaceType = 0; + + // 0 = no modifier + private int modifier = 0; + /** * Key code of the button that is bound */ @@ -40,6 +46,18 @@ public Macro(UUID umid, int keyCode, CommandInterface command, boolean active, b this.keyCode = keyCode; this.command = command; this.active = active; + this.interfaceType = 0; + this.modifier = 0; + this.repeat = repeat; + } + + public Macro(UUID umid, int keyCode, CommandInterface command, int interfaceType, int modifier, boolean active, boolean repeat) { + this.umid = umid; + this.keyCode = keyCode; + this.command = command; + this.active = active; + this.interfaceType = interfaceType; + this.modifier = modifier; this.repeat = repeat; } @@ -101,4 +119,28 @@ public Macro setRepeat(boolean repeat) { return this; } + @Override + public Macro setInterfaceType(int interfaceType) { + this.interfaceType = interfaceType; + + return this; + } + + @Override + public int getInterfaceType() { + return this.interfaceType; + } + + @Override + public Macro setModifier(int modifier) { + this.modifier = modifier; + + return this; + } + + @Override + public int getModifier() { + return this.modifier; + } + } diff --git a/src/main/java/com/mattsmeets/macrokey/model/MacroInterface.java b/src/main/java/com/mattsmeets/macrokey/model/MacroInterface.java index 7854e84..9e8e6ea 100644 --- a/src/main/java/com/mattsmeets/macrokey/model/MacroInterface.java +++ b/src/main/java/com/mattsmeets/macrokey/model/MacroInterface.java @@ -74,4 +74,10 @@ public interface MacroInterface { * @return the current Macro instance */ Macro setRepeat(boolean repeat); + + Macro setInterfaceType(int interfaceType); + int getInterfaceType(); + + Macro setModifier(int modifier); + int getModifier(); } diff --git a/src/main/java/com/mattsmeets/macrokey/repository/BindingsRepository.java b/src/main/java/com/mattsmeets/macrokey/repository/BindingsRepository.java index 4207482..1b3c28d 100644 --- a/src/main/java/com/mattsmeets/macrokey/repository/BindingsRepository.java +++ b/src/main/java/com/mattsmeets/macrokey/repository/BindingsRepository.java @@ -239,7 +239,7 @@ MacroInterface findMacroByUUID(UUID ulid, boolean sync) throws IOException { * @return list of active macro's with the given keyCode as trigger * @throws IOException when file can not be found or read */ - public Set findMacroByKeyCode(int keyCode, LayerInterface layer, boolean sync) throws IOException { + public Set findMacroByKeyCode(int keyCode, int interfaceType, int modifiers, LayerInterface layer, boolean sync) throws IOException { if (sync) { // if specified to update memory with latest changes loadConfiguration(); @@ -257,6 +257,8 @@ public Set findMacroByKeyCode(int keyCode, LayerInterface layer, .filter( macro -> macro.getKeyCode() == keyCode + && macro.getInterfaceType() == interfaceType + && macro.getModifier() == modifiers && macro.isActive() && isMacroInLayer(macro, layer) )