Skip to content

Commit

Permalink
Fix hold repeat key (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
valterc committed Oct 12, 2022
1 parent d625722 commit bbeae9a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/src/main/java/com/valterc/ki2/input/InputManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private SwitchKeyEvent convertSwitchToSwitchKey(SwitchEvent switchEvent) {

if (karooCommand.first == null) {
Pair<KarooKey, SwitchCommandType> newKarooCommand = getKarooCommand(switchEvent.getType(), karooCommand.second);

if (newKarooCommand == null) {
Timber.w("Unable to retranslate command, original: {switch=%s, command=%s}, target: {switch=%s, command=%s}",
switchEvent.getType(),
Expand All @@ -81,6 +82,11 @@ private SwitchKeyEvent convertSwitchToSwitchKey(SwitchEvent switchEvent) {
return null;
}

if (switchEvent.getCommand() == SwitchCommand.LONG_PRESS_UP && newKarooCommand.second != SwitchCommandType.HOLD){
// Avoid repeating key press on LONG_PRESS_UP
return null;
}

karooCommand = newKarooCommand;
}

Expand Down Expand Up @@ -113,9 +119,8 @@ private SwitchKeyEvent getSwitchKeyEvent(SwitchEvent switchEvent, Pair<KarooKey,
return null;
}

KarooKey karooKey = karooCommand.first;

if (karooCommand.second == SwitchCommandType.HOLD) {
// If the commandtype is HOLD then use the original command (LONG_PRESS_DOWN, LONG_PRESS_CONTINUE, LONG_PRESS_UP)
return new SwitchKeyEvent(karooCommand.first, switchEvent.getCommand(), switchEvent.getRepeat());
} else {
return new SwitchKeyEvent(karooCommand.first, karooCommand.second.getCommand(), switchEvent.getRepeat());
Expand Down

0 comments on commit bbeae9a

Please sign in to comment.