|
|
|
@ -1,6 +1,10 @@ |
|
|
|
|
package mightypork.gamecore.input; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
|
|
import mightypork.gamecore.logging.Log; |
|
|
|
|
|
|
|
|
|
import org.lwjgl.input.Keyboard; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -9,135 +13,252 @@ import org.lwjgl.input.Keyboard; |
|
|
|
|
* |
|
|
|
|
* @author MightyPork |
|
|
|
|
*/ |
|
|
|
|
public interface Keys { |
|
|
|
|
public class Keys { |
|
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
|
|
|
|
|
|
public static final int NONE = 0x00; |
|
|
|
|
|
|
|
|
|
public static final int ESCAPE = 0x01; |
|
|
|
|
|
|
|
|
|
public static final int NUM_1 = 0x02; |
|
|
|
|
public static final int NUM_2 = 0x03; |
|
|
|
|
public static final int NUM_3 = 0x04; |
|
|
|
|
public static final int NUM_4 = 0x05; |
|
|
|
|
public static final int NUM_5 = 0x06; |
|
|
|
|
public static final int NUM_6 = 0x07; |
|
|
|
|
public static final int NUM_7 = 0x08; |
|
|
|
|
public static final int NUM_8 = 0x09; |
|
|
|
|
public static final int NUM_9 = 0x0A; |
|
|
|
|
public static final int NUM_0 = 0x0B; |
|
|
|
|
|
|
|
|
|
public static final int Q = 0x10; |
|
|
|
|
public static final int W = 0x11; |
|
|
|
|
public static final int E = 0x12; |
|
|
|
|
public static final int R = 0x13; |
|
|
|
|
public static final int T = 0x14; |
|
|
|
|
public static final int Y = 0x15; |
|
|
|
|
public static final int U = 0x16; |
|
|
|
|
public static final int I = 0x17; |
|
|
|
|
public static final int O = 0x18; |
|
|
|
|
public static final int P = 0x19; |
|
|
|
|
public static final int A = 0x1E; |
|
|
|
|
public static final int S = 0x1F; |
|
|
|
|
public static final int D = 0x20; |
|
|
|
|
public static final int F = 0x21; |
|
|
|
|
public static final int G = 0x22; |
|
|
|
|
public static final int H = 0x23; |
|
|
|
|
public static final int J = 0x24; |
|
|
|
|
public static final int K = 0x25; |
|
|
|
|
public static final int L = 0x26; |
|
|
|
|
public static final int Z = 0x2C; |
|
|
|
|
public static final int X = 0x2D; |
|
|
|
|
public static final int C = 0x2E; |
|
|
|
|
public static final int V = 0x2F; |
|
|
|
|
public static final int B = 0x30; |
|
|
|
|
public static final int N = 0x31; |
|
|
|
|
public static final int M = 0x32; |
|
|
|
|
|
|
|
|
|
public static final int MINUS = 0x0C; |
|
|
|
|
public static final int EQUALS = 0x0D; |
|
|
|
|
public static final int SLASH = 0x35; |
|
|
|
|
public static final int BACKSLASH = 0x2B; |
|
|
|
|
public static final int L_BRACKET = 0x1A; |
|
|
|
|
public static final int R_BRACKET = 0x1B; |
|
|
|
|
public static final int SEMICOLON = 0x27; |
|
|
|
|
public static final int APOSTROPHE = 0x28; |
|
|
|
|
public static final int GRAVE = 0x29; |
|
|
|
|
public static final int COMMA = 0x33; |
|
|
|
|
public static final int PERIOD = 0x34; |
|
|
|
|
|
|
|
|
|
public static final int SPACE = 0x39; |
|
|
|
|
public static final int BACKSPACE = 0x0E; |
|
|
|
|
public static final int TAB = 0x0F; |
|
|
|
|
|
|
|
|
|
public static final int F1 = 0x3B; |
|
|
|
|
public static final int F2 = 0x3C; |
|
|
|
|
public static final int F3 = 0x3D; |
|
|
|
|
public static final int F4 = 0x3E; |
|
|
|
|
public static final int F5 = 0x3F; |
|
|
|
|
public static final int F6 = 0x40; |
|
|
|
|
public static final int F7 = 0x41; |
|
|
|
|
public static final int F8 = 0x42; |
|
|
|
|
public static final int F9 = 0x43; |
|
|
|
|
public static final int F10 = 0x44; |
|
|
|
|
public static final int F11 = 0x57; |
|
|
|
|
public static final int F12 = 0x58; |
|
|
|
|
public static final int F13 = 0x64; |
|
|
|
|
public static final int F14 = 0x65; |
|
|
|
|
public static final int F15 = 0x66; |
|
|
|
|
|
|
|
|
|
public static final int CAPS_LOCK = 0x3A; |
|
|
|
|
public static final int SCROLL_LOCK = 0x46; |
|
|
|
|
public static final int NUM_LOCK = 0x45; |
|
|
|
|
|
|
|
|
|
public static final int SUBTRACT = 0x4A; /* - on numeric keypad */ |
|
|
|
|
public static final int ADD = 0x4E; /* + on numeric keypad */ |
|
|
|
|
public static final int NUMPAD_0 = 0x52; |
|
|
|
|
public static final int NUMPAD_1 = 0x4F; |
|
|
|
|
public static final int NUMPAD_2 = 0x50; |
|
|
|
|
public static final int NUMPAD_3 = 0x51; |
|
|
|
|
public static final int NUMPAD_4 = 0x4B; |
|
|
|
|
public static final int NUMPAD_5 = 0x4C; |
|
|
|
|
public static final int NUMPAD_6 = 0x4D; |
|
|
|
|
public static final int NUMPAD_7 = 0x47; |
|
|
|
|
public static final int NUMPAD_8 = 0x48; |
|
|
|
|
public static final int NUMPAD_9 = 0x49; |
|
|
|
|
public static final int DECIMAL = 0x53; /* . on numeric keypad */ |
|
|
|
|
public static final int NUMPAD_ENTER = 0x9C; /* Enter on numeric keypad */ |
|
|
|
|
public static final int DIVIDE = 0xB5; /* / on numeric keypad */ |
|
|
|
|
public static final int MULTIPLY = 0x37; /* * on numeric keypad */ |
|
|
|
|
|
|
|
|
|
public static final int L_CONTROL = 0x1D; |
|
|
|
|
public static final int R_CONTROL = 0x9D; |
|
|
|
|
public static final int L_ALT = 0x38; |
|
|
|
|
public static final int R_ALT = 0xB8; |
|
|
|
|
public static final int L_SHIFT = 0x2A; |
|
|
|
|
public static final int R_SHIFT = 0x36; |
|
|
|
|
public static final int L_META = 0xDB; |
|
|
|
|
public static final int R_META = 0xDC; |
|
|
|
|
|
|
|
|
|
public static final int UP = 0xC8; /* UpArrow on arrow keypad */ |
|
|
|
|
public static final int DOWN = 0xD0; /* DownArrow on arrow keypad */ |
|
|
|
|
public static final int LEFT = 0xCB; /* LeftArrow on arrow keypad */ |
|
|
|
|
public static final int RIGHT = 0xCD; /* RightArrow on arrow keypad */ |
|
|
|
|
|
|
|
|
|
public static final int HOME = 0xC7; /* Home on arrow keypad */ |
|
|
|
|
public static final int END = 0xCF; /* End on arrow keypad */ |
|
|
|
|
|
|
|
|
|
public static final int PAGE_UP = 0xC9; /* PgUp on arrow keypad */ |
|
|
|
|
public static final int PAGE_DOWN = 0xD1; /* PgDn on arrow keypad */ |
|
|
|
|
|
|
|
|
|
public static final int RETURN = 0x1C; |
|
|
|
|
public static final int PAUSE = 0xC5; /* Pause */ |
|
|
|
|
public static final int INSERT = 0xD2; /* Insert on arrow keypad */ |
|
|
|
|
public static final int DELETE = 0xD3; /* Delete on arrow keypad */ |
|
|
|
|
|
|
|
|
|
public static final byte MOD_NONE = 0; |
|
|
|
|
public static final byte MOD_ALT = 1; |
|
|
|
|
public static final byte MOD_CONTROL = 2; |
|
|
|
|
public static final byte MOD_SHIFT = 4; |
|
|
|
|
public static final byte MOD_META = 8; |
|
|
|
|
public static final int NONE = Keyboard.KEY_NONE; |
|
|
|
|
|
|
|
|
|
public static final int ESCAPE = Keyboard.KEY_ESCAPE; |
|
|
|
|
|
|
|
|
|
public static final int NUM_1 = Keyboard.KEY_1; |
|
|
|
|
public static final int NUM_2 = Keyboard.KEY_2; |
|
|
|
|
public static final int NUM_3 = Keyboard.KEY_3; |
|
|
|
|
public static final int NUM_4 = Keyboard.KEY_4; |
|
|
|
|
public static final int NUM_5 = Keyboard.KEY_5; |
|
|
|
|
public static final int NUM_6 = Keyboard.KEY_6; |
|
|
|
|
public static final int NUM_7 = Keyboard.KEY_7; |
|
|
|
|
public static final int NUM_8 = Keyboard.KEY_8; |
|
|
|
|
public static final int NUM_9 = Keyboard.KEY_9; |
|
|
|
|
public static final int NUM_0 = Keyboard.KEY_0; |
|
|
|
|
|
|
|
|
|
public static final int Q = Keyboard.KEY_Q; |
|
|
|
|
public static final int W = Keyboard.KEY_W; |
|
|
|
|
public static final int E = Keyboard.KEY_E; |
|
|
|
|
public static final int R = Keyboard.KEY_R; |
|
|
|
|
public static final int T = Keyboard.KEY_T; |
|
|
|
|
public static final int Y = Keyboard.KEY_Y; |
|
|
|
|
public static final int U = Keyboard.KEY_U; |
|
|
|
|
public static final int I = Keyboard.KEY_I; |
|
|
|
|
public static final int O = Keyboard.KEY_O; |
|
|
|
|
public static final int P = Keyboard.KEY_P; |
|
|
|
|
public static final int A = Keyboard.KEY_A; |
|
|
|
|
public static final int S = Keyboard.KEY_S; |
|
|
|
|
public static final int D = Keyboard.KEY_D; |
|
|
|
|
public static final int F = Keyboard.KEY_F; |
|
|
|
|
public static final int G = Keyboard.KEY_G; |
|
|
|
|
public static final int H = Keyboard.KEY_H; |
|
|
|
|
public static final int J = Keyboard.KEY_J; |
|
|
|
|
public static final int K = Keyboard.KEY_K; |
|
|
|
|
public static final int L = Keyboard.KEY_L; |
|
|
|
|
public static final int Z = Keyboard.KEY_Z; |
|
|
|
|
public static final int X = Keyboard.KEY_X; |
|
|
|
|
public static final int C = Keyboard.KEY_C; |
|
|
|
|
public static final int V = Keyboard.KEY_V; |
|
|
|
|
public static final int B = Keyboard.KEY_B; |
|
|
|
|
public static final int N = Keyboard.KEY_N; |
|
|
|
|
public static final int M = Keyboard.KEY_M; |
|
|
|
|
|
|
|
|
|
public static final int MINUS = Keyboard.KEY_MINUS; |
|
|
|
|
public static final int EQUALS = Keyboard.KEY_EQUALS; |
|
|
|
|
public static final int SLASH = Keyboard.KEY_SLASH; |
|
|
|
|
public static final int BACKSLASH = Keyboard.KEY_BACKSLASH; |
|
|
|
|
public static final int L_BRACKET = Keyboard.KEY_LBRACKET; |
|
|
|
|
public static final int R_BRACKET = Keyboard.KEY_RBRACKET; |
|
|
|
|
public static final int SEMICOLON = Keyboard.KEY_SEMICOLON; |
|
|
|
|
public static final int APOSTROPHE = Keyboard.KEY_APOSTROPHE; |
|
|
|
|
public static final int GRAVE = Keyboard.KEY_GRAVE; |
|
|
|
|
public static final int COMMA = Keyboard.KEY_COMMA; |
|
|
|
|
public static final int PERIOD = Keyboard.KEY_PERIOD; |
|
|
|
|
|
|
|
|
|
public static final int SPACE = Keyboard.KEY_SPACE; |
|
|
|
|
public static final int BACKSPACE = Keyboard.KEY_BACK; |
|
|
|
|
public static final int TAB = Keyboard.KEY_TAB; |
|
|
|
|
|
|
|
|
|
public static final int F1 = Keyboard.KEY_F1; |
|
|
|
|
public static final int F2 = Keyboard.KEY_F2; |
|
|
|
|
public static final int F3 = Keyboard.KEY_F3; |
|
|
|
|
public static final int F4 = Keyboard.KEY_F4; |
|
|
|
|
public static final int F5 = Keyboard.KEY_F5; |
|
|
|
|
public static final int F6 = Keyboard.KEY_F6; |
|
|
|
|
public static final int F7 = Keyboard.KEY_F7; |
|
|
|
|
public static final int F8 = Keyboard.KEY_F8; |
|
|
|
|
public static final int F9 = Keyboard.KEY_F9; |
|
|
|
|
public static final int F10 = Keyboard.KEY_F10; |
|
|
|
|
public static final int F11 = Keyboard.KEY_F11; |
|
|
|
|
public static final int F12 = Keyboard.KEY_F12; |
|
|
|
|
public static final int F13 = Keyboard.KEY_F13; |
|
|
|
|
public static final int F14 = Keyboard.KEY_F14; |
|
|
|
|
public static final int F15 = Keyboard.KEY_F15; |
|
|
|
|
|
|
|
|
|
public static final int CAPS_LOCK = Keyboard.KEY_CAPITAL; |
|
|
|
|
public static final int SCROLL_LOCK = Keyboard.KEY_SCROLL; |
|
|
|
|
public static final int NUM_LOCK = Keyboard.KEY_NUMLOCK; |
|
|
|
|
|
|
|
|
|
public static final int NUMPAD_MINUS = Keyboard.KEY_SUBTRACT; |
|
|
|
|
public static final int NUMPAD_PLUSS = Keyboard.KEY_ADD; |
|
|
|
|
public static final int NUMPAD_0 = Keyboard.KEY_NUMPAD0; |
|
|
|
|
public static final int NUMPAD_1 = Keyboard.KEY_NUMPAD1; |
|
|
|
|
public static final int NUMPAD_2 = Keyboard.KEY_NUMPAD2; |
|
|
|
|
public static final int NUMPAD_3 = Keyboard.KEY_NUMPAD3; |
|
|
|
|
public static final int NUMPAD_4 = Keyboard.KEY_NUMPAD4; |
|
|
|
|
public static final int NUMPAD_5 = Keyboard.KEY_NUMPAD5; |
|
|
|
|
public static final int NUMPAD_6 = Keyboard.KEY_NUMPAD6; |
|
|
|
|
public static final int NUMPAD_7 = Keyboard.KEY_NUMPAD7; |
|
|
|
|
public static final int NUMPAD_8 = Keyboard.KEY_NUMPAD8; |
|
|
|
|
public static final int NUMPAD_9 = Keyboard.KEY_NUMPAD9; |
|
|
|
|
public static final int NUMPAD_DECIMAL = Keyboard.KEY_DECIMAL; |
|
|
|
|
public static final int NUMPAD_ENTER = Keyboard.KEY_NUMPADENTER; |
|
|
|
|
public static final int NUMPAD_DIVIDE = Keyboard.KEY_DIVIDE; |
|
|
|
|
public static final int NUMPAD_MULTIPLY = Keyboard.KEY_MULTIPLY; |
|
|
|
|
|
|
|
|
|
public static final int L_CONTROL = Keyboard.KEY_LCONTROL; |
|
|
|
|
public static final int R_CONTROL = Keyboard.KEY_RCONTROL; |
|
|
|
|
public static final int L_ALT = Keyboard.KEY_LMENU; |
|
|
|
|
public static final int R_ALT = Keyboard.KEY_RMENU; |
|
|
|
|
public static final int L_SHIFT = Keyboard.KEY_LSHIFT; |
|
|
|
|
public static final int R_SHIFT = Keyboard.KEY_RSHIFT; |
|
|
|
|
public static final int L_META = Keyboard.KEY_LMETA; |
|
|
|
|
public static final int R_META = Keyboard.KEY_RMETA; |
|
|
|
|
|
|
|
|
|
public static final int UP = Keyboard.KEY_UP; |
|
|
|
|
public static final int DOWN = Keyboard.KEY_DOWN; |
|
|
|
|
public static final int LEFT = Keyboard.KEY_LEFT; |
|
|
|
|
public static final int RIGHT = Keyboard.KEY_RIGHT; |
|
|
|
|
|
|
|
|
|
public static final int HOME = Keyboard.KEY_HOME; |
|
|
|
|
public static final int END = Keyboard.KEY_END; |
|
|
|
|
|
|
|
|
|
public static final int PAGE_UP = Keyboard.KEY_PRIOR; |
|
|
|
|
public static final int PAGE_DOWN = Keyboard.KEY_NEXT; |
|
|
|
|
|
|
|
|
|
public static final int RETURN = Keyboard.KEY_RETURN; |
|
|
|
|
public static final int PAUSE = Keyboard.KEY_PAUSE; |
|
|
|
|
public static final int INSERT = Keyboard.KEY_INSERT; |
|
|
|
|
public static final int DELETE = Keyboard.KEY_DELETE; |
|
|
|
|
|
|
|
|
|
public static final byte MOD_NONE = 0; |
|
|
|
|
public static final byte MOD_ALT = 1; |
|
|
|
|
public static final byte MOD_CONTROL = 2; |
|
|
|
|
public static final byte MOD_SHIFT = 4; |
|
|
|
|
public static final byte MOD_META = 8; |
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
private static HashMap<String, String> loadAliasMap = new HashMap<>(); |
|
|
|
|
private static HashMap<String, String> saveAliasMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
static { |
|
|
|
|
// init maps
|
|
|
|
|
loadAliasMap.put("ENTER", "RETURN"); |
|
|
|
|
loadAliasMap.put("PGDN", "NEXT"); |
|
|
|
|
loadAliasMap.put("PGUP", "PRIOR"); |
|
|
|
|
loadAliasMap.put("PAGE_DOWN", "NEXT"); |
|
|
|
|
loadAliasMap.put("PAGE_UP", "PRIOR"); |
|
|
|
|
loadAliasMap.put("SPACEBAR", "SPACE"); |
|
|
|
|
loadAliasMap.put("ESC", "ESCAPE"); |
|
|
|
|
loadAliasMap.put("NUMPAD_DIVIDE", "DIVIDE"); |
|
|
|
|
loadAliasMap.put("NUMPAD_MULTIPLY", "MULTIPLY"); |
|
|
|
|
loadAliasMap.put("NUMPAD_ADD", "ADD"); |
|
|
|
|
loadAliasMap.put("NUMPAD_SUBTRACT", "SUBTRACT"); |
|
|
|
|
loadAliasMap.put("CAPS_LOCK", "CAPITAL"); |
|
|
|
|
loadAliasMap.put("SCROLL_LOCK", "SROLL"); |
|
|
|
|
loadAliasMap.put("NUM_LOCK", "NUMLOCK"); |
|
|
|
|
loadAliasMap.put("BACKSPACE", "BACK"); |
|
|
|
|
|
|
|
|
|
saveAliasMap.put("RETURN", "ENTER"); |
|
|
|
|
saveAliasMap.put("NEXT", "PAGE_DOWN"); |
|
|
|
|
saveAliasMap.put("PRIOR", "PAGE_UP"); |
|
|
|
|
saveAliasMap.put("DIVIDE", "NUMPAD_DIVIDE"); |
|
|
|
|
saveAliasMap.put("MULTIPLY", "NUMPAD_MULTIPLY"); |
|
|
|
|
saveAliasMap.put("ADD", "NUMPAD_ADD"); |
|
|
|
|
saveAliasMap.put("SUBTRACT", "NUMPAD_SUBTRACT"); |
|
|
|
|
saveAliasMap.put("CAPITAL", "CAPS_LOCK"); |
|
|
|
|
saveAliasMap.put("SROLL", "SCROLL_LOCK"); |
|
|
|
|
saveAliasMap.put("NUMLOCK", "NUM_LOCK"); |
|
|
|
|
saveAliasMap.put("BACK", "BACKSPACE"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static int keyFromString(String key) |
|
|
|
|
{ |
|
|
|
|
String key1 = key; |
|
|
|
|
if (loadAliasMap.containsKey(key1)) key1 = loadAliasMap.get(key1); |
|
|
|
|
|
|
|
|
|
final int index = Keyboard.getKeyIndex(key1); |
|
|
|
|
if (index == Keys.NONE && !key1.equals("NONE")) { |
|
|
|
|
Log.w("Could not parse key: " + key + " (" + key1 + ")"); |
|
|
|
|
} |
|
|
|
|
return index; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static int modFromString(String mod) |
|
|
|
|
{ |
|
|
|
|
int mod_mask = Keys.MOD_NONE; |
|
|
|
|
|
|
|
|
|
if (mod.contains("CTRL")) { |
|
|
|
|
mod_mask |= Keys.MOD_CONTROL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mod.contains("ALT")) { |
|
|
|
|
mod_mask |= Keys.MOD_ALT; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mod.contains("SHIFT")) { |
|
|
|
|
mod_mask |= Keys.MOD_SHIFT; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mod.contains("META") || mod.contains("WIN")) { |
|
|
|
|
mod_mask |= Keys.MOD_META; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return mod_mask; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String modToString(int mod) |
|
|
|
|
{ |
|
|
|
|
String s = ""; |
|
|
|
|
|
|
|
|
|
if ((mod & Keys.MOD_CONTROL) != 0) { |
|
|
|
|
s += "CTRL+"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ((mod & Keys.MOD_ALT) != 0) { |
|
|
|
|
s += "ALT+"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ((mod & Keys.MOD_SHIFT) != 0) { |
|
|
|
|
s += "SHIFT+"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ((mod & Keys.MOD_META) != 0) { |
|
|
|
|
s += "META+"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String keyToString(int key) |
|
|
|
|
{ |
|
|
|
|
String s = Keyboard.getKeyName(key); |
|
|
|
|
if (saveAliasMap.containsKey(s)) s = saveAliasMap.get(s); |
|
|
|
|
if (s == null) { |
|
|
|
|
Log.w("Could not stringify key: " + key); |
|
|
|
|
s = "NONE"; |
|
|
|
|
} |
|
|
|
|
return s.toUpperCase(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static int keyToMod(int key) |
|
|
|
|
{ |
|
|
|
|
if (key == L_SHIFT || key == R_SHIFT) return MOD_SHIFT; |
|
|
|
|
if (key == L_CONTROL || key == R_CONTROL) return MOD_CONTROL; |
|
|
|
|
if (key == L_ALT || key == R_ALT) return MOD_ALT; |
|
|
|
|
if (key == L_META || key == R_META) return MOD_META; |
|
|
|
|
return MOD_NONE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|