Skip to content

Commit

Permalink
ToKeyAction: fixed KeyStroke not being pressed if more than one ToKey…
Browse files Browse the repository at this point in the history
…Action maps the exact same KeyStroke with activation = REPEAT
  • Loading branch information
bwRavencl committed Aug 30, 2023
1 parent b80bc39 commit 8f19400
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

@Action(label = "BUTTON_TO_CYCLE_ACTION", category = ActionCategory.BUTTON, order = 140)
public final class ButtonToCycleAction extends DescribableAction<Byte>
implements IButtonToAction, IResetableAction, IActivatableAction<Byte> {
implements IActivatableAction<Byte>, IButtonToAction, IResetableAction<Byte> {

private transient Activatable activatable = Activatable.YES;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.lwjgl.glfw.GLFW;

@Action(label = "BUTTON_TO_MODE_ACTION", category = ActionCategory.BUTTON, order = 145)
public final class ButtonToModeAction implements IButtonToAction, IResetableAction {
public final class ButtonToModeAction implements IButtonToAction, IResetableAction<Byte> {

private static final LinkedList<ButtonToModeAction> buttonToModeActionStack = new LinkedList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
label = "BUTTON_TO_SELECT_ON_SCREEN_KEYBOARD_KEY_ACTION",
category = ActionCategory.ON_SCREEN_KEYBOARD_MODE,
order = 510)
public final class ButtonToSelectOnScreenKeyboardKeyAction implements IButtonToAction, IResetableAction {
public final class ButtonToSelectOnScreenKeyboardKeyAction implements IButtonToAction, IResetableAction<Byte> {

private static final long INITIAL_MIN_ELAPSE_TIME = 250L;
private static final long PEAK_MIN_ELAPSE_TIME = 90L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import de.bwravencl.controllerbuddy.input.Input;

public interface IResetableAction extends IAction<Byte> {
public interface IResetableAction<V extends Number> extends IAction<V> {

void reset(final Input input);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.text.MessageFormat;

public abstract class ToKeyAction<V extends Number> extends DescribableAction<V>
implements IActivatableAction<V>, ILongPressAction<V> {
implements IActivatableAction<V>, ILongPressAction<V>, IResetableAction<V> {

@ActionProperty(label = "ACTIVATION", editorBuilder = ActivationEditorBuilder.class, order = 11)
private Activation activation = Activation.REPEAT;
Expand All @@ -39,6 +39,8 @@ public abstract class ToKeyAction<V extends Number> extends DescribableAction<V>

private transient Activatable activatable;

private transient boolean wasDown;

@Override
public Object clone() throws CloneNotSupportedException {
final var toKeyAction = (ToKeyAction<?>) super.clone();
Expand Down Expand Up @@ -77,8 +79,15 @@ void handleAction(final boolean hot, final Input input) {
switch (activation) {
case REPEAT -> {
final var downKeyStrokes = input.getDownKeyStrokes();
if (!hot) downKeyStrokes.remove(keystroke);
else downKeyStrokes.add(keystroke);
if (!hot) {
if (wasDown) {
downKeyStrokes.remove(keystroke);
wasDown = false;
}
} else {
downKeyStrokes.add(keystroke);
wasDown = true;
}
}
case SINGLE_IMMEDIATELY -> {
if (!hot) activatable = Activatable.YES;
Expand All @@ -104,6 +113,11 @@ public boolean isLongPress() {
return longPress;
}

@Override
public void reset(final Input input) {
wasDown = false;
}

@Override
public void setActivatable(final Activatable activatable) {
this.activatable = activatable;
Expand Down

0 comments on commit 8f19400

Please sign in to comment.