/** * Provides an enumeration of different keybard keys that can be checked for * in the terminal window. This includes all letters (upper or lower case), * digits, punctuation, and the arrow keys, enter, backspace and escape. * Some keys (such as Alt, Shift, or Control) are impossible to detect with * this. Others (such as the "Function" keys, Home, End or Page up) are not * implemented at this time */ public enum Key { // control / whitespace TAB (9), ENTER (13), ESCAPE (27), SPACE (32), // punctuation EXCLAIM (33), QUOTEDBL (34), HASH (35), DOLLAR (36), PERCENT (37), AMPERSAND (38), QUOTE (39), LEFTPAREN (40), RIGHTPAREN (41), ASTERISK (42), PLUS (43), COMMA (44), MINUS (45), DOT (46), FORWARDSLASH (47), // numeric digits D0 (48), D1 (49), D2 (50), D3 (51), D4 (52), D5 (53), D6 (54), D7 (55), D8 (56), D9 (57), // more punctuation COLON (58), SEMICOLON (59), LESS (60), EQUALS (61), GREATER (62), QUESTION (63), AT (64), // capital letters A (65), B (66), C (67), D (68), E (69), F (70), G (71), H (72), I (73), J (74), K (75), L (76), M (77), N (78), O (79), P (80), Q (81), R (82), S (83), T (84), U (85), V (86), W (87), X (88), Y (89), Z (90), // even more punctuation LEFTBRACKET (91), BACKSLASH (92), RIGHTBRACKET (93), CARET (94), UNDERSCORE (95), BACKQUOTE (96), // lower case letters a (97), b (98), c (99), d (100), e (101), f (102), g (103), h (104), i (105), j (106), k (107), l (108), m (109), n (110), o (111), p (112), q (113), r (114), s (115), t (116), u (117), v (118), w (119), x (120), y (121), z (122), // still more punctuation LEFTBRACE (123), VERTICALBAR (124), RIGHTBRACE (125), TILDE (126), BACKSPACE (127), // arrow keys (these have no ascii values!) RIGHT (0), LEFT (0), DOWN (0), UP (0), // dummy key for unhandeled keys NONE (0); // the ascii value associated with this key (or 0 for none) private int ascii; // construct a Key from an ASCII code Key(int ascii) { this.ascii = ascii; } /** * Returns the ASCII code (if any) associated with the key. * The arrow keys will return 0 since there is no ASCII value for them * @return the ASCII value, or 0 if none is associated with the key */ public int getCode() { return ascii; } }