com.github.xpenatan.gdx.backends.teavm.utils.KeyCodes Maven / Gradle / Ivy
Show all versions of backend-teavm Show documentation
package com.github.xpenatan.gdx.backends.teavm.utils;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.Input.Keys;
/**
* @author xpenatan
*/
public class KeyCodes {
/**
* The left JS mouse button.
*/
private static final int BUTTON_LEFT = 0;
/**
* The middle JS mouse button.
*/
private static final int BUTTON_MIDDLE = 1;
/**
* The right JS mouse button.
*/
private static final int BUTTON_RIGHT = 2;
/**
* Key code for A
*/
public static final int KEY_A = 65;
/**
* Key code for B
*/
public static final int KEY_B = 66;
/**
* Key code for C
*/
public static final int KEY_C = 67;
/**
* Key code for D
*/
public static final int KEY_D = 68;
/**
* Key code for E
*/
public static final int KEY_E = 69;
/**
* Key code for F
*/
public static final int KEY_F = 70;
/**
* Key code for G
*/
public static final int KEY_G = 71;
/**
* Key code for H
*/
public static final int KEY_H = 72;
/**
* Key code for I
*/
public static final int KEY_I = 73;
/**
* Key code for J
*/
public static final int KEY_J = 74;
/**
* Key code for K
*/
public static final int KEY_K = 75;
/**
* Key code for L
*/
public static final int KEY_L = 76;
/**
* Key code for M
*/
public static final int KEY_M = 77;
/**
* Key code for N
*/
public static final int KEY_N = 78;
/**
* Key code for O
*/
public static final int KEY_O = 79;
/**
* Key code for P
*/
public static final int KEY_P = 80;
/**
* Key code for Q
*/
public static final int KEY_Q = 81;
/**
* Key code for R
*/
public static final int KEY_R = 82;
/**
* Key code for S
*/
public static final int KEY_S = 83;
/**
* Key code for T
*/
public static final int KEY_T = 84;
/**
* Key code for U
*/
public static final int KEY_U = 85;
/**
* Key code for V
*/
public static final int KEY_V = 86;
/**
* Key code for W
*/
public static final int KEY_W = 87;
/**
* Key code for X
*/
public static final int KEY_X = 88;
/**
* Key code for Y
*/
public static final int KEY_Y = 89;
/**
* Key code for Z
*/
public static final int KEY_Z = 90;
/**
* Key code number 0
*/
public static final int KEY_ZERO = 48;
/**
* Key code number 1
*/
public static final int KEY_ONE = 49;
/**
* Key code number 2
*/
public static final int KEY_TWO = 50;
/**
* Key code number 3
*/
public static final int KEY_THREE = 51;
/**
* Key code number 4
*/
public static final int KEY_FOUR = 52;
/**
* Key code number 5
*/
public static final int KEY_FIVE = 53;
/**
* Key code number 6
*/
public static final int KEY_SIX = 54;
/**
* Key code number 7
*/
public static final int KEY_SEVEN = 55;
/**
* Key code number 8
*/
public static final int KEY_EIGHT = 56;
/**
* Key code number 9
*/
public static final int KEY_NINE = 57;
/**
* Key code for number 0 on numeric keyboard
*/
public static final int KEY_NUM_ZERO = 96;
/**
* Key code for number 1 on numeric keyboard
*/
public static final int KEY_NUM_ONE = 97;
/**
* Key code for number 2 on numeric keyboard
*/
public static final int KEY_NUM_TWO = 98;
/**
* Key code for number 3 on numeric keyboard
*/
public static final int KEY_NUM_THREE = 99;
/**
* Key code for number 4 on numeric keyboard
*/
public static final int KEY_NUM_FOUR = 100;
/**
* Key code for number 5 on numeric keyboard
*/
public static final int KEY_NUM_FIVE = 101;
/**
* Key code for number 6 on numeric keyboard
*/
public static final int KEY_NUM_SIX = 102;
/**
* Key code for number 7 on numeric keyboard
*/
public static final int KEY_NUM_SEVEN = 103;
/**
* Key code for number 8 on numeric keyboard
*/
public static final int KEY_NUM_EIGHT = 104;
/**
* Key code for number 9 on numeric keyboard
*/
public static final int KEY_NUM_NINE = 105;
/**
* Key code for multiply on numeric keyboard
*/
public static final int KEY_NUM_MULTIPLY = 106;
/**
* Key code for plus on numeric keyboard
*/
public static final int KEY_NUM_PLUS = 107;
/**
* Key code for minus on numeric keyboard
*/
public static final int KEY_NUM_MINUS = 109;
/**
* Key code for period on numeric keyboard
*/
public static final int KEY_NUM_PERIOD = 110;
/**
* Key code for division on numeric keyboard
*/
public static final int KEY_NUM_DIVISION = 111;
/**
* Alt key code.
*/
public static final int KEY_ALT = 18;
/**
* Backspace key code.
*/
public static final int KEY_BACKSPACE = 8;
/**
* Control key code.
*/
public static final int KEY_CTRL = 17;
/**
* Delete key code (also numeric keypad delete).
*/
public static final int KEY_DELETE = 46;
/**
* Down arrow code (Also numeric keypad down).
*/
public static final int KEY_DOWN = 40;
/**
* End key code (Also numeric keypad south west).
*/
public static final int KEY_END = 35;
/**
* Enter key code.
*/
public static final int KEY_ENTER = 13;
/**
* Escape key code.
*/
public static final int KEY_ESCAPE = 27;
/**
* Home key code (Also numeric keypad north west).
*/
public static final int KEY_HOME = 36;
/**
* Left key code (Also numeric keypad west).
*/
public static final int KEY_LEFT = 37;
/**
* Page down key code (Also numeric keypad south east).
*/
public static final int KEY_PAGEDOWN = 34;
/**
* Page up key code (Also numeric keypad north east).
*/
public static final int KEY_PAGEUP = 33;
/**
* Right arrow key code (Also numeric keypad east).
*/
public static final int KEY_RIGHT = 39;
/**
* Shift key code.
*/
public static final int KEY_SHIFT = 16;
/**
* Tab key code.
*/
public static final int KEY_TAB = 9;
/**
* Up Arrow key code (Also numeric keypad north).
*/
public static final int KEY_UP = 38;
/**
* Key code for F1
*/
public static final int KEY_F1 = 112;
/**
* Key code for F2
*/
public static final int KEY_F2 = 113;
/**
* Key code for F3
*/
public static final int KEY_F3 = 114;
/**
* Key code for F4
*/
public static final int KEY_F4 = 115;
/**
* Key code for F5
*/
public static final int KEY_F5 = 116;
/**
* Key code for F6
*/
public static final int KEY_F6 = 117;
/**
* Key code for F7
*/
public static final int KEY_F7 = 118;
/**
* Key code for F8
*/
public static final int KEY_F8 = 119;
/**
* Key code for F9
*/
public static final int KEY_F9 = 120;
/**
* Key code for F10
*/
public static final int KEY_F10 = 121;
/**
* Key code for F11
*/
public static final int KEY_F11 = 122;
/**
* Key code for F12
*/
public static final int KEY_F12 = 123;
/**
* Key code for Windows key on Firefox Linux
*/
public static final int KEY_WIN_KEY_FF_LINUX = 0;
/**
* Key code for Mac enter key
*/
public static final int KEY_MAC_ENTER = 3;
/**
* Key code for pause key
*/
public static final int KEY_PAUSE = 19;
/**
* Key code for caps lock key
*/
public static final int KEY_CAPS_LOCK = 20;
/**
* Key code for space
*/
public static final int KEY_SPACE = 32;
/**
* Key code for print key
*/
public static final int KEY_PRINT_SCREEN = 44;
/**
* Key code for insert key (Also numeric keyboard insert).
*/
public static final int KEY_INSERT = 45; // also NUM_INSERT
/**
* Key code for insert key (Also num lock on FF,Safari Mac).
*/
public static final int KEY_NUM_CENTER = 12;
/**
* Key code for left windows key.
*/
public static final int KEY_WIN_KEY = 224;
/**
* Key code for left windows key or meta.
*/
public static final int KEY_WIN_KEY_LEFT_META = 91;
/**
* Key code for right windows key.
*/
public static final int KEY_WIN_KEY_RIGHT = 92;
/**
* Key code for context menu key.
*/
public static final int KEY_CONTEXT_MENU = 93;
/**
* Key code for {@link KeyCodes#KEY_WIN_KEY_LEFT_META} that Firefox fires
* for the meta key.
*/
public static final int KEY_MAC_FF_META = 224; // Firefox (Gecko) fires this for the meta key instead of 91
/**
* Key code for num lock.
*/
public static final int KEY_NUMLOCK = 144;
/**
* Key code for scroll lock.
*/
public static final int KEY_SCROLL_LOCK = 145;
/**
* Key code for first OS specific media key (like volume).
*/
public static final int KEY_FIRST_MEDIA_KEY = 166;
/**
* Key code for last OS specific media key (like volume).
*/
public static final int KEY_LAST_MEDIA_KEY = 183;
/**
* Key code for IME.
*/
public static final int KEY_WIN_IME = 229;
private static final int KEY_0 = 48;
private static final int KEY_1 = 49;
private static final int KEY_2 = 50;
private static final int KEY_3 = 51;
private static final int KEY_4 = 52;
private static final int KEY_5 = 53;
private static final int KEY_6 = 54;
private static final int KEY_7 = 55;
private static final int KEY_8 = 56;
private static final int KEY_9 = 57;
private static final int KEY_LEFT_WINDOW_KEY = 91;
private static final int KEY_RIGHT_WINDOW_KEY = 92;
private static final int KEY_SELECT_KEY = 93;
private static final int KEY_NUMPAD0 = 96;
private static final int KEY_NUMPAD1 = 97;
private static final int KEY_NUMPAD2 = 98;
private static final int KEY_NUMPAD3 = 99;
private static final int KEY_NUMPAD4 = 100;
private static final int KEY_NUMPAD5 = 101;
private static final int KEY_NUMPAD6 = 102;
private static final int KEY_NUMPAD7 = 103;
private static final int KEY_NUMPAD8 = 104;
private static final int KEY_NUMPAD9 = 105;
private static final int KEY_MULTIPLY = 106;
private static final int KEY_ADD = 107;
private static final int KEY_SUBTRACT = 109;
private static final int KEY_DECIMAL_POINT_KEY = 110;
private static final int KEY_DIVIDE = 111;
private static final int KEY_NUM_LOCK = 144;
private static final int KEY_SEMICOLON = 186;
private static final int KEY_EQUALS = 187;
private static final int KEY_COMMA = 188;
private static final int KEY_DASH = 189;
private static final int KEY_PERIOD = 190;
private static final int KEY_FORWARD_SLASH = 191;
private static final int KEY_GRAVE_ACCENT = 192;
private static final int KEY_OPEN_BRACKET = 219;
private static final int KEY_BACKSLASH = 220;
private static final int KEY_CLOSE_BRACKET = 221;
private static final int KEY_SINGLE_QUOTE = 222;
/**
* Determines if a key code is an arrow key.
*/
public static boolean isArrowKey(int code) {
switch(code) {
case KEY_DOWN:
case KEY_RIGHT:
case KEY_UP:
case KEY_LEFT:
return true;
default:
return false;
}
}
/**
* Update arrow keys for left and right based on current locale.
*
*
* Note: this method is used internally by built-in GWT widgets but could be
* renamed/refactored without notice.
*
* This method simplifies RTL handling in your code:
* int keyCode = KeyCodes.maybeSwapArrowKeysForRtl(event.getKeyCode(),
* LocaleInfo.getCurrentLocale().isRTL());
* switch (keyCode) {
* case KeyCodes.KEY_LEFT:
* ... // start of the line, no special RTL handling
* break;
* case KeyCodes.KEY_RIGHT:
* ... // end of the line, no special RTL handling
* break;
* ...
* }
*
*/
public static int maybeSwapArrowKeysForRtl(int code, boolean isRtl) {
if(isRtl) {
if(code == KEY_RIGHT) {
code = KEY_LEFT;
}
else if(code == KEY_LEFT) {
code = KEY_RIGHT;
}
}
return code;
}
// This class should never be instantiated
private KeyCodes() {
}
public static int keyForCode(int keyCode) {
switch(keyCode) {
case KeyCodes.KEY_ALT:
return Keys.ALT_LEFT;
case KeyCodes.KEY_BACKSPACE:
return Keys.BACKSPACE;
case KeyCodes.KEY_CTRL:
return Keys.CONTROL_LEFT;
case KeyCodes.KEY_DELETE:
return Keys.FORWARD_DEL;
case KeyCodes.KEY_DOWN:
return Keys.DOWN;
case KeyCodes.KEY_END:
return Keys.END;
case KeyCodes.KEY_ENTER:
return Keys.ENTER;
case KeyCodes.KEY_ESCAPE:
return Keys.ESCAPE;
case KeyCodes.KEY_HOME:
return Keys.HOME;
case KeyCodes.KEY_LEFT:
return Keys.LEFT;
case KeyCodes.KEY_PAGEDOWN:
return Keys.PAGE_DOWN;
case KeyCodes.KEY_PAGEUP:
return Keys.PAGE_UP;
case KeyCodes.KEY_RIGHT:
return Keys.RIGHT;
case KeyCodes.KEY_SHIFT:
return Keys.SHIFT_LEFT;
case KeyCodes.KEY_TAB:
return Keys.TAB;
case KeyCodes.KEY_UP:
return Keys.UP;
case KeyCodes.KEY_PAUSE:
return Keys.UNKNOWN; // FIXME
case KeyCodes.KEY_CAPS_LOCK:
return Keys.UNKNOWN; // FIXME
case KeyCodes.KEY_SPACE:
return Keys.SPACE;
case KeyCodes.KEY_INSERT:
return Keys.INSERT;
case KeyCodes.KEY_0:
return Keys.NUM_0;
case KeyCodes.KEY_1:
return Keys.NUM_1;
case KeyCodes.KEY_2:
return Keys.NUM_2;
case KeyCodes.KEY_3:
return Keys.NUM_3;
case KeyCodes.KEY_4:
return Keys.NUM_4;
case KeyCodes.KEY_5:
return Keys.NUM_5;
case KeyCodes.KEY_6:
return Keys.NUM_6;
case KeyCodes.KEY_7:
return Keys.NUM_7;
case KeyCodes.KEY_8:
return Keys.NUM_8;
case KeyCodes.KEY_9:
return Keys.NUM_9;
case KeyCodes.KEY_A:
return Keys.A;
case KeyCodes.KEY_B:
return Keys.B;
case KeyCodes.KEY_C:
return Keys.C;
case KeyCodes.KEY_D:
return Keys.D;
case KeyCodes.KEY_E:
return Keys.E;
case KeyCodes.KEY_F:
return Keys.F;
case KeyCodes.KEY_G:
return Keys.G;
case KeyCodes.KEY_H:
return Keys.H;
case KeyCodes.KEY_I:
return Keys.I;
case KeyCodes.KEY_J:
return Keys.J;
case KeyCodes.KEY_K:
return Keys.K;
case KeyCodes.KEY_L:
return Keys.L;
case KeyCodes.KEY_M:
return Keys.M;
case KeyCodes.KEY_N:
return Keys.N;
case KeyCodes.KEY_O:
return Keys.O;
case KeyCodes.KEY_P:
return Keys.P;
case KeyCodes.KEY_Q:
return Keys.Q;
case KeyCodes.KEY_R:
return Keys.R;
case KeyCodes.KEY_S:
return Keys.S;
case KeyCodes.KEY_T:
return Keys.T;
case KeyCodes.KEY_U:
return Keys.U;
case KeyCodes.KEY_V:
return Keys.V;
case KeyCodes.KEY_W:
return Keys.W;
case KeyCodes.KEY_X:
return Keys.X;
case KeyCodes.KEY_Y:
return Keys.Y;
case KeyCodes.KEY_Z:
return Keys.Z;
case KeyCodes.KEY_LEFT_WINDOW_KEY:
return Keys.UNKNOWN; // FIXME
case KeyCodes.KEY_RIGHT_WINDOW_KEY:
return Keys.UNKNOWN; // FIXME
// case KEY_SELECT_KEY: return Keys.SELECT_KEY;
case KeyCodes.KEY_NUMPAD0:
return Keys.NUMPAD_0;
case KeyCodes.KEY_NUMPAD1:
return Keys.NUMPAD_1;
case KeyCodes.KEY_NUMPAD2:
return Keys.NUMPAD_2;
case KeyCodes.KEY_NUMPAD3:
return Keys.NUMPAD_3;
case KeyCodes.KEY_NUMPAD4:
return Keys.NUMPAD_4;
case KeyCodes.KEY_NUMPAD5:
return Keys.NUMPAD_5;
case KeyCodes.KEY_NUMPAD6:
return Keys.NUMPAD_6;
case KeyCodes.KEY_NUMPAD7:
return Keys.NUMPAD_7;
case KeyCodes.KEY_NUMPAD8:
return Keys.NUMPAD_8;
case KeyCodes.KEY_NUMPAD9:
return Keys.NUMPAD_9;
case KeyCodes.KEY_MULTIPLY:
return Keys.UNKNOWN; // FIXME
case KeyCodes.KEY_ADD:
return Keys.PLUS;
case KeyCodes.KEY_SUBTRACT:
return Keys.MINUS;
case KeyCodes.KEY_DECIMAL_POINT_KEY:
return Keys.PERIOD;
case KeyCodes.KEY_DIVIDE:
return Keys.UNKNOWN; // FIXME
case KeyCodes.KEY_F1:
return Keys.F1;
case KeyCodes.KEY_F2:
return Keys.F2;
case KeyCodes.KEY_F3:
return Keys.F3;
case KeyCodes.KEY_F4:
return Keys.F4;
case KeyCodes.KEY_F5:
return Keys.F5;
case KeyCodes.KEY_F6:
return Keys.F6;
case KeyCodes.KEY_F7:
return Keys.F7;
case KeyCodes.KEY_F8:
return Keys.F8;
case KeyCodes.KEY_F9:
return Keys.F9;
case KeyCodes.KEY_F10:
return Keys.F10;
case KeyCodes.KEY_F11:
return Keys.F11;
case KeyCodes.KEY_F12:
return Keys.F12;
case KeyCodes.KEY_NUM_LOCK:
return Keys.NUM;
case KeyCodes.KEY_SCROLL_LOCK:
return Keys.UNKNOWN; // FIXME
case KeyCodes.KEY_SEMICOLON:
return Keys.SEMICOLON;
case KeyCodes.KEY_EQUALS:
return Keys.EQUALS;
case KeyCodes.KEY_COMMA:
return Keys.COMMA;
case KeyCodes.KEY_DASH:
return Keys.MINUS;
case KeyCodes.KEY_PERIOD:
return Keys.PERIOD;
case KeyCodes.KEY_FORWARD_SLASH:
return Keys.SLASH;
case KeyCodes.KEY_GRAVE_ACCENT:
return Keys.UNKNOWN; // FIXME
case KeyCodes.KEY_OPEN_BRACKET:
return Keys.LEFT_BRACKET;
case KeyCodes.KEY_BACKSLASH:
return Keys.BACKSLASH;
case KeyCodes.KEY_CLOSE_BRACKET:
return Keys.RIGHT_BRACKET;
case KeyCodes.KEY_SINGLE_QUOTE:
return Keys.APOSTROPHE;
default:
return Keys.UNKNOWN;
}
}
public static int getButton(int button) {
if(button == BUTTON_LEFT) return Buttons.LEFT;
if(button == BUTTON_RIGHT) return Buttons.RIGHT;
if(button == BUTTON_MIDDLE) return Buttons.MIDDLE;
return Buttons.LEFT;
}
}