Skip to content
Merged
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
32 changes: 23 additions & 9 deletions src/main/java/qupath/fx/controls/InputDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,21 @@ public class InputDisplay implements EventHandler<InputEvent> {
private static final String mouseItemClass = "mouse-item";
private static final PseudoClass pseudoClassActive = PseudoClass.getPseudoClass("active");

// Keys
// Main modifier keys
private static final Set<KeyCode> MODIFIER_KEYS = Set.of(
KeyCode.SHIFT,
KeyCode.SHORTCUT,
KeyCode.COMMAND,
KeyCode.CONTROL,
KeyCode.ALT,
KeyCode.ALT_GRAPH
KeyCode.ALT_GRAPH,
KeyCode.WINDOWS
);

// Buttons
// Keys that can be locked
private static final Set<KeyCode> LOCKABLE_KEYS = Set.of(KeyCode.CAPS, KeyCode.NUM_LOCK);

// Buttons
private final BooleanProperty primaryDown = new SimpleBooleanProperty(false);
private final BooleanProperty secondaryDown = new SimpleBooleanProperty(false);
private final BooleanProperty middleDown = new SimpleBooleanProperty(false);
Expand Down Expand Up @@ -594,11 +598,13 @@ public void handle(KeyEvent event) {
logger.trace("Skipping text input to {}", event.getTarget());
return;
}

boolean isLockable = LOCKABLE_KEYS.contains(code);
boolean isModifier = MODIFIER_KEYS.contains(code);
if (event.getEventType() == KeyEvent.KEY_PRESSED) {
if (isModifier) {
currentModifiers.add(code);
if (isModifier || isLockable) {
if (!isLockable || Platform.isKeyLocked(code).orElse(Boolean.FALSE)) {
currentModifiers.add(code);
}
updateModifierText();
} else {
// Inconveniently, we can't get a reliable text representation from the keycode
Expand All @@ -608,8 +614,10 @@ public void handle(KeyEvent event) {
}
removePending.remove(code);
} else if (event.getEventType() == KeyEvent.KEY_RELEASED) {
if (removePending.add(code)) {
Platform.runLater(this::handleRemove);
if (!isLockable || !Platform.isKeyLocked(code).orElse(Boolean.FALSE)) {
if (removePending.add(code)) {
Platform.runLater(this::handleRemove);
}
}
}

Expand All @@ -633,7 +641,7 @@ private void handleRemove() {
private String getText(KeyEvent event) {
String text = event.getText();
if (event.getCode().isLetterKey())
return text.toUpperCase();
return event.getCode().getName().toUpperCase();
if (text.trim().isEmpty())
return getText(event.getCode());
return text;
Expand Down Expand Up @@ -673,6 +681,12 @@ private static String getSymbol(KeyCode code) {
case TAB -> isMac ? "⇥" : "↹";
case SPACE -> "␣";
case ESCAPE -> "Esc";
case WINDOWS -> "Win";
case CAPS -> "⇪";
case HOME -> "⇱";
case END -> "⇲";
case PAGE_UP -> "⇞";
case PAGE_DOWN -> "⇟";
default -> null;
};
}
Expand Down