Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: [Feature] Modifiers and mouse buttons #75

Open
wants to merge 2 commits into
base: 1.17-2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<MacroInterface> macroList = bindingsRepository.findMacroByKeyCode(keyCode, modState.getActiveLayer(), false);
final Set<MacroInterface> macroList = bindingsRepository.findMacroByKeyCode(keyCode, interfaceType, modifier, modState.getActiveLayer(), false);
if (macroList.isEmpty()) {
return;
}
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/com/mattsmeets/macrokey/model/Macro.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MacroInterface> findMacroByKeyCode(int keyCode, LayerInterface layer, boolean sync) throws IOException {
public Set<MacroInterface> findMacroByKeyCode(int keyCode, int interfaceType, int modifiers, LayerInterface layer, boolean sync) throws IOException {
if (sync) {
// if specified to update memory with latest changes
loadConfiguration();
Expand All @@ -257,6 +257,8 @@ public Set<MacroInterface> findMacroByKeyCode(int keyCode, LayerInterface layer,
.filter(
macro ->
macro.getKeyCode() == keyCode
&& macro.getInterfaceType() == interfaceType
&& macro.getModifier() == modifiers
&& macro.isActive()
&& isMacroInLayer(macro, layer)
)
Expand Down