Code refactoring
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / gui / humaninput / KeyboardHelper.java
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/KeyboardHelper.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/KeyboardHelper.java
new file mode 100644 (file)
index 0000000..44b861e
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Sixth 3D engine. Author: Svjatoslav Agejenko. 
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.sixth.e3d.gui.humaninput;
+
+import java.awt.event.InputEvent;
+import java.util.HashSet;
+import java.util.Set;
+
+public class KeyboardHelper {
+
+    public static final int TAB = 9;
+    public static final int DOWN = 40;
+    public static final int UP = 38;
+    public static final int RIGHT = 39;
+    public static final int LEFT = 37;
+    public static final int PGDOWN = 34;
+    public static final int PGUP = 33;
+    public static final int HOME = 36;
+    public static final int END = 35;
+    public static final int DEL = 127;
+    public static final int ENTER = 10;
+    public static final int BACKSPACE = 8;
+    public static final int ESC = 27;
+    public static final int SHIFT = 16;
+
+    private static final Set<Integer> nonText;
+
+    static {
+        nonText = new HashSet<>();
+        nonText.add(DOWN);
+        nonText.add(UP);
+        nonText.add(LEFT);
+        nonText.add(RIGHT);
+
+        nonText.add(SHIFT);
+        nonText.add(ESC);
+    }
+
+    public static boolean isAltPressed(final int modifiersEx) {
+        return (modifiersEx | InputEvent.ALT_DOWN_MASK) == modifiersEx;
+    }
+
+    public static boolean isCtrlPressed(final int modifiersEx) {
+        return (modifiersEx | InputEvent.CTRL_DOWN_MASK) == modifiersEx;
+    }
+
+    public static boolean isShiftPressed(final int modifiersEx) {
+        return (modifiersEx | InputEvent.SHIFT_DOWN_MASK) == modifiersEx;
+    }
+
+    public static boolean isText(final int keyCode) {
+        return !nonText.contains(keyCode);
+    }
+
+}