From adafd1a0af00bc73ac9f68971fd83d91a41d9575 Mon Sep 17 00:00:00 2001 From: matthewsmeets Date: Tue, 9 Nov 2021 22:13:47 +0100 Subject: [PATCH 1/2] Adding support for modifiers and buttons to the core --- .../handler/hook/KeyInputHandler.java | 17 ++++++-- .../com/mattsmeets/macrokey/model/Macro.java | 42 +++++++++++++++++++ .../macrokey/model/MacroInterface.java | 6 +++ .../repository/BindingsRepository.java | 4 +- 4 files changed, 63 insertions(+), 6 deletions(-) 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..5d1a73f 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,20 @@ 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; + if(event instanceof InputEvent.KeyInputEvent) { + keyCode = ((InputEvent.KeyInputEvent) event).getKey(); + keyIsDown = ((InputEvent.KeyInputEvent) event).getAction() == GLFW.GLFW_PRESS; + } else if(event instanceof InputEvent.RawMouseEvent) { + keyCode = ((InputEvent.RawMouseEvent) event).getButton(); + keyIsDown = ((InputEvent.RawMouseEvent) event).getAction() == GLFW.GLFW_PRESS; + interfaceType = 1; + } - final Set macroList = bindingsRepository.findMacroByKeyCode(keyCode, modState.getActiveLayer(), false); + final Set macroList = bindingsRepository.findMacroByKeyCode(keyCode, interfaceType, 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..92d1a51 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 0; + } + + @Override + public Macro setModifier(int modifier) { + this.modifier = modifier; + +return this; + } + + @Override + public int getModifier() { + return 0; + } + } 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..879ae12 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, LayerInterface layer, boolean sync) throws IOException { if (sync) { // if specified to update memory with latest changes loadConfiguration(); @@ -256,7 +256,7 @@ public Set findMacroByKeyCode(int keyCode, LayerInterface layer, .stream() .filter( macro -> - macro.getKeyCode() == keyCode + macro.getKeyCode() == keyCode && macro.getInterfaceType() == interfaceType && macro.isActive() && isMacroInLayer(macro, layer) ) From e32057dde8fb931fc64e3ef635a14203e9206bae Mon Sep 17 00:00:00 2001 From: matthewsmeets Date: Tue, 9 Nov 2021 22:28:48 +0100 Subject: [PATCH 2/2] complete support --- .../macrokey/handler/hook/KeyInputHandler.java | 10 ++++++++-- src/main/java/com/mattsmeets/macrokey/model/Macro.java | 6 +++--- .../macrokey/repository/BindingsRepository.java | 6 ++++-- 3 files changed, 15 insertions(+), 7 deletions(-) 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 5d1a73f..a024bc9 100644 --- a/src/main/java/com/mattsmeets/macrokey/handler/hook/KeyInputHandler.java +++ b/src/main/java/com/mattsmeets/macrokey/handler/hook/KeyInputHandler.java @@ -32,16 +32,22 @@ 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; - } else if(event instanceof InputEvent.RawMouseEvent) { + 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, interfaceType, 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 92d1a51..fca7d7a 100644 --- a/src/main/java/com/mattsmeets/macrokey/model/Macro.java +++ b/src/main/java/com/mattsmeets/macrokey/model/Macro.java @@ -128,19 +128,19 @@ public Macro setInterfaceType(int interfaceType) { @Override public int getInterfaceType() { - return 0; + return this.interfaceType; } @Override public Macro setModifier(int modifier) { this.modifier = modifier; -return this; + return this; } @Override public int getModifier() { - return 0; + return this.modifier; } } diff --git a/src/main/java/com/mattsmeets/macrokey/repository/BindingsRepository.java b/src/main/java/com/mattsmeets/macrokey/repository/BindingsRepository.java index 879ae12..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, int interfaceType, 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(); @@ -256,7 +256,9 @@ public Set findMacroByKeyCode(int keyCode, int interfaceType, La .stream() .filter( macro -> - macro.getKeyCode() == keyCode && macro.getInterfaceType() == interfaceType + macro.getKeyCode() == keyCode + && macro.getInterfaceType() == interfaceType + && macro.getModifier() == modifiers && macro.isActive() && isMacroInLayer(macro, layer) )