-
Notifications
You must be signed in to change notification settings - Fork 534
Expand file tree
/
Copy pathLayoutIndependentKeys.java
More file actions
34 lines (29 loc) · 977 Bytes
/
Copy pathLayoutIndependentKeys.java
File metadata and controls
34 lines (29 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package software.coley.recaf.util;
import jakarta.annotation.Nonnull;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
public final class LayoutIndependentKeys {
private LayoutIndependentKeys() {
}
@Nonnull
public static KeyCode resolveKeyCode(@Nonnull KeyEvent event) {
KeyCode resolved = resolveFromControlCharacter(event);
return resolved != null ? resolved : event.getCode();
}
public static boolean isModified(@Nonnull KeyEvent event, @Nonnull KeyCode code) {
if (resolveKeyCode(event) != code)
return false;
return event.isControlDown() || event.isMetaDown();
}
private static KeyCode resolveFromControlCharacter(@Nonnull KeyEvent event) {
if (!event.isControlDown() && !event.isMetaDown())
return null;
String character = event.getCharacter();
if (character.isEmpty())
return null;
char c = character.charAt(0);
if (c < 1 || c > 26)
return null;
return NodeEvents.getKeycode((char) ('a' + c - 1));
}
}