From d29bb62b927201a0bf203e456b48e00b1a233157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Costa?= Date: Sun, 19 Nov 2023 15:25:17 +0100 Subject: [PATCH 1/4] Add more SDL key mappings --- .../minart/backend/SdlKeyMapping.scala | 162 +++++++++++------- .../minart/input/KeyboardInput.scala | 39 +++++ 2 files changed, 142 insertions(+), 59 deletions(-) diff --git a/backend/native/src/main/scala/eu/joaocosta/minart/backend/SdlKeyMapping.scala b/backend/native/src/main/scala/eu/joaocosta/minart/backend/SdlKeyMapping.scala index df6618a6..5dcc0ced 100644 --- a/backend/native/src/main/scala/eu/joaocosta/minart/backend/SdlKeyMapping.scala +++ b/backend/native/src/main/scala/eu/joaocosta/minart/backend/SdlKeyMapping.scala @@ -9,52 +9,56 @@ import eu.joaocosta.minart.input.KeyboardInput.* */ object SdlKeyMapping extends KeyMapping[SDL_KeyCode] { protected val mappings: Map[SDL_KeyCode, Key] = Map( - SDLK_a -> Key.A, - SDLK_b -> Key.B, - SDLK_c -> Key.C, - SDLK_d -> Key.D, - SDLK_e -> Key.E, - SDLK_f -> Key.F, - SDLK_g -> Key.G, - SDLK_h -> Key.H, - SDLK_i -> Key.I, - SDLK_j -> Key.J, - SDLK_k -> Key.K, - SDLK_l -> Key.L, - SDLK_m -> Key.M, - SDLK_n -> Key.N, - SDLK_o -> Key.O, - SDLK_p -> Key.P, - SDLK_q -> Key.Q, - SDLK_r -> Key.R, - SDLK_s -> Key.S, - SDLK_t -> Key.T, - SDLK_u -> Key.U, - SDLK_v -> Key.V, - SDLK_w -> Key.W, - SDLK_x -> Key.X, - SDLK_y -> Key.Y, - SDLK_z -> Key.Z, - SDLK_0 -> Key.Digit0, - SDLK_1 -> Key.Digit1, - SDLK_2 -> Key.Digit2, - SDLK_3 -> Key.Digit3, - SDLK_4 -> Key.Digit4, - SDLK_5 -> Key.Digit5, - SDLK_6 -> Key.Digit6, - SDLK_7 -> Key.Digit7, - SDLK_8 -> Key.Digit8, - SDLK_9 -> Key.Digit9, - SDLK_KP_0 -> Key.NumPad0, - SDLK_KP_1 -> Key.NumPad1, - SDLK_KP_2 -> Key.NumPad2, - SDLK_KP_3 -> Key.NumPad3, - SDLK_KP_4 -> Key.NumPad4, - SDLK_KP_5 -> Key.NumPad5, - SDLK_KP_6 -> Key.NumPad6, - SDLK_KP_7 -> Key.NumPad7, - SDLK_KP_8 -> Key.NumPad8, - SDLK_KP_9 -> Key.NumPad9, + // Letters + SDLK_a -> Key.A, + SDLK_b -> Key.B, + SDLK_c -> Key.C, + SDLK_d -> Key.D, + SDLK_e -> Key.E, + SDLK_f -> Key.F, + SDLK_g -> Key.G, + SDLK_h -> Key.H, + SDLK_i -> Key.I, + SDLK_j -> Key.J, + SDLK_k -> Key.K, + SDLK_l -> Key.L, + SDLK_m -> Key.M, + SDLK_n -> Key.N, + SDLK_o -> Key.O, + SDLK_p -> Key.P, + SDLK_q -> Key.Q, + SDLK_r -> Key.R, + SDLK_s -> Key.S, + SDLK_t -> Key.T, + SDLK_u -> Key.U, + SDLK_v -> Key.V, + SDLK_w -> Key.W, + SDLK_x -> Key.X, + SDLK_y -> Key.Y, + SDLK_z -> Key.Z, + // Numbers + SDLK_0 -> Key.Digit0, + SDLK_1 -> Key.Digit1, + SDLK_2 -> Key.Digit2, + SDLK_3 -> Key.Digit3, + SDLK_4 -> Key.Digit4, + SDLK_5 -> Key.Digit5, + SDLK_6 -> Key.Digit6, + SDLK_7 -> Key.Digit7, + SDLK_8 -> Key.Digit8, + SDLK_9 -> Key.Digit9, + // Numpad Numbers + SDLK_KP_0 -> Key.NumPad0, + SDLK_KP_1 -> Key.NumPad1, + SDLK_KP_2 -> Key.NumPad2, + SDLK_KP_3 -> Key.NumPad3, + SDLK_KP_4 -> Key.NumPad4, + SDLK_KP_5 -> Key.NumPad5, + SDLK_KP_6 -> Key.NumPad6, + SDLK_KP_7 -> Key.NumPad7, + SDLK_KP_8 -> Key.NumPad8, + SDLK_KP_9 -> Key.NumPad9, + // Whitespace SDLK_SPACE -> Key.Space, SDLK_KP_SPACE -> Key.Space, SDLK_TAB -> Key.Tab, @@ -64,18 +68,58 @@ object SdlKeyMapping extends KeyMapping[SDL_KeyCode] { SDLK_KP_ENTER -> Key.Enter, SDLK_BACKSPACE -> Key.Backspace, SDLK_KP_BACKSPACE -> Key.Backspace, - SDLK_ESCAPE -> Key.Escape, - SDLK_LSHIFT -> Key.Shift, - SDLK_RSHIFT -> Key.Shift, - SDLK_LCTRL -> Key.Ctrl, - SDLK_RCTRL -> Key.Ctrl, - SDLK_LALT -> Key.Alt, - SDLK_RALT -> Key.Alt, - SDLK_LGUI -> Key.Meta, - SDLK_RGUI -> Key.Meta, - SDLK_UP -> Key.Up, - SDLK_DOWN -> Key.Down, - SDLK_LEFT -> Key.Left, - SDLK_RIGHT -> Key.Right + // Control + SDLK_ESCAPE -> Key.Escape, + SDLK_LSHIFT -> Key.Shift, + SDLK_RSHIFT -> Key.Shift, + SDLK_LCTRL -> Key.Ctrl, + SDLK_RCTRL -> Key.Ctrl, + SDLK_LALT -> Key.Alt, + SDLK_RALT -> Key.Alt, + SDLK_LGUI -> Key.Meta, + SDLK_RGUI -> Key.Meta, + // Arrows + SDLK_UP -> Key.Up, + SDLK_DOWN -> Key.Down, + SDLK_LEFT -> Key.Left, + SDLK_RIGHT -> Key.Right, + // Punctuation + SDLK_PERIOD -> Key.Period, + SDLK_KP_PERIOD -> Key.Period, + SDLK_COLON -> Key.Colon, + SDLK_KP_COLON -> Key.Colon, + SDLK_COMMA -> Key.Comma, + SDLK_SEMICOLON -> Key.Semicolon, + SDLK_EXCLAIM -> Key.ExclamationMark, + SDLK_KP_EXCLAM -> Key.ExclamationMark, + SDLK_QUESTION -> Key.QuestionMark, + // Quotes + SDLK_QUOTE -> Key.SingleQuote, + SDLK_QUOTEDBL -> Key.DoubleQuote, + // Slashes + SDLK_SLASH -> Key.Slash, + SDLK_KP_DIVIDE -> Key.Slash, + SDLK_BACKSLASH -> Key.Backslash, + SDLK_KP_VERTICALBAR -> Key.VerticalBar, + SDLK_UNDERSCORE -> Key.Underscore, + // Math + SDLK_PLUS -> Key.Plus, + SDLK_KP_PLUS -> Key.Plus, + SDLK_MINUS -> Key.Minus, + SDLK_KP_MINUS -> Key.Minus, + SDLK_ASTERISK -> Key.Asterisk, + SDLK_EQUALS -> Key.Equals, + SDLK_KP_EQUALS -> Key.Equals, + // Brackets + SDLK_LEFTPAREN -> Key.OpenParenthesis, + SDLK_KP_LEFTPAREN -> Key.OpenParenthesis, + SDLK_RIGHTPAREN -> Key.CloseParenthesis, + SDLK_KP_RIGHTPAREN -> Key.CloseParenthesis, + // Other + SDLK_AMPERSAND -> Key.Ampersand, + SDLK_KP_AMPERSAND -> Key.Ampersand, + SDLK_DOLLAR -> Key.DollarSign, + SDLK_KP_AT -> Key.At, + SDLK_AT -> Key.At ) } diff --git a/core/shared/src/main/scala/eu/joaocosta/minart/input/KeyboardInput.scala b/core/shared/src/main/scala/eu/joaocosta/minart/input/KeyboardInput.scala index 744a5a67..e2835cb1 100644 --- a/core/shared/src/main/scala/eu/joaocosta/minart/input/KeyboardInput.scala +++ b/core/shared/src/main/scala/eu/joaocosta/minart/input/KeyboardInput.scala @@ -81,6 +81,7 @@ object KeyboardInput { /** Platform-agnostic identifier for a keyboard key. */ enum Key { + // Letters case A case B case C @@ -108,6 +109,7 @@ object KeyboardInput { case Y case Z + // Numbers case Digit0 case Digit1 case Digit2 @@ -119,6 +121,7 @@ object KeyboardInput { case Digit8 case Digit9 + // Numpad Numbers case NumPad0 case NumPad1 case NumPad2 @@ -130,20 +133,56 @@ object KeyboardInput { case NumPad8 case NumPad9 + // Whitespace case Space case Tab case Enter case Backspace + // Control case Escape case Shift case Ctrl case Alt case Meta + // Arrows case Up case Down case Left case Right + + // Punctuation + case Period + case Colon + case Comma + case Semicolon + case ExclamationMark + case QuestionMark + + // Quotes + case SingleQuote + case DoubleQuote + + // Slashes + case Slash + case Backslash + case VerticalBar + case Underscore + + // Math + case Plus + case Minus + case Asterisk + case Equals + + // Brackets + case OpenParenthesis + case CloseParenthesis + + // Other + case Ampersand + case DollarSign + case At } } From ea12f7c53883d9954ad6edf95c6de601ae1a0126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Costa?= Date: Sun, 19 Nov 2023 19:37:28 +0100 Subject: [PATCH 2/4] Add more AWT Key Mappings --- .../minart/backend/AwtKeyMapping.scala | 148 +++++++++++------- .../minart/backend/SdlKeyMapping.scala | 25 ++- .../minart/input/KeyboardInput.scala | 2 - 3 files changed, 104 insertions(+), 71 deletions(-) diff --git a/backend/jvm/src/main/scala/eu/joaocosta/minart/backend/AwtKeyMapping.scala b/backend/jvm/src/main/scala/eu/joaocosta/minart/backend/AwtKeyMapping.scala index 31d9388c..b55fa7f8 100644 --- a/backend/jvm/src/main/scala/eu/joaocosta/minart/backend/AwtKeyMapping.scala +++ b/backend/jvm/src/main/scala/eu/joaocosta/minart/backend/AwtKeyMapping.scala @@ -8,65 +8,101 @@ import eu.joaocosta.minart.input.KeyboardInput.* */ object AwtKeyMapping extends KeyMapping[Int] { protected val mappings: Map[Int, Key] = Map( - KeyEvent.VK_A -> Key.A, - KeyEvent.VK_B -> Key.B, - KeyEvent.VK_C -> Key.C, - KeyEvent.VK_D -> Key.D, - KeyEvent.VK_E -> Key.E, - KeyEvent.VK_F -> Key.F, - KeyEvent.VK_G -> Key.G, - KeyEvent.VK_H -> Key.H, - KeyEvent.VK_I -> Key.I, - KeyEvent.VK_J -> Key.J, - KeyEvent.VK_K -> Key.K, - KeyEvent.VK_L -> Key.L, - KeyEvent.VK_M -> Key.M, - KeyEvent.VK_N -> Key.N, - KeyEvent.VK_O -> Key.O, - KeyEvent.VK_P -> Key.P, - KeyEvent.VK_Q -> Key.Q, - KeyEvent.VK_R -> Key.R, - KeyEvent.VK_S -> Key.S, - KeyEvent.VK_T -> Key.T, - KeyEvent.VK_U -> Key.U, - KeyEvent.VK_V -> Key.V, - KeyEvent.VK_W -> Key.W, - KeyEvent.VK_X -> Key.X, - KeyEvent.VK_Y -> Key.Y, - KeyEvent.VK_Z -> Key.Z, - KeyEvent.VK_0 -> Key.Digit0, - KeyEvent.VK_1 -> Key.Digit1, - KeyEvent.VK_2 -> Key.Digit2, - KeyEvent.VK_3 -> Key.Digit3, - KeyEvent.VK_4 -> Key.Digit4, - KeyEvent.VK_5 -> Key.Digit5, - KeyEvent.VK_6 -> Key.Digit6, - KeyEvent.VK_7 -> Key.Digit7, - KeyEvent.VK_8 -> Key.Digit8, - KeyEvent.VK_9 -> Key.Digit9, - KeyEvent.VK_NUMPAD0 -> Key.NumPad0, - KeyEvent.VK_NUMPAD1 -> Key.NumPad1, - KeyEvent.VK_NUMPAD2 -> Key.NumPad2, - KeyEvent.VK_NUMPAD3 -> Key.NumPad3, - KeyEvent.VK_NUMPAD4 -> Key.NumPad4, - KeyEvent.VK_NUMPAD5 -> Key.NumPad5, - KeyEvent.VK_NUMPAD6 -> Key.NumPad6, - KeyEvent.VK_NUMPAD7 -> Key.NumPad7, - KeyEvent.VK_NUMPAD8 -> Key.NumPad8, - KeyEvent.VK_NUMPAD9 -> Key.NumPad9, - KeyEvent.VK_ESCAPE -> Key.Escape, + // Letters + KeyEvent.VK_A -> Key.A, + KeyEvent.VK_B -> Key.B, + KeyEvent.VK_C -> Key.C, + KeyEvent.VK_D -> Key.D, + KeyEvent.VK_E -> Key.E, + KeyEvent.VK_F -> Key.F, + KeyEvent.VK_G -> Key.G, + KeyEvent.VK_H -> Key.H, + KeyEvent.VK_I -> Key.I, + KeyEvent.VK_J -> Key.J, + KeyEvent.VK_K -> Key.K, + KeyEvent.VK_L -> Key.L, + KeyEvent.VK_M -> Key.M, + KeyEvent.VK_N -> Key.N, + KeyEvent.VK_O -> Key.O, + KeyEvent.VK_P -> Key.P, + KeyEvent.VK_Q -> Key.Q, + KeyEvent.VK_R -> Key.R, + KeyEvent.VK_S -> Key.S, + KeyEvent.VK_T -> Key.T, + KeyEvent.VK_U -> Key.U, + KeyEvent.VK_V -> Key.V, + KeyEvent.VK_W -> Key.W, + KeyEvent.VK_X -> Key.X, + KeyEvent.VK_Y -> Key.Y, + KeyEvent.VK_Z -> Key.Z, + // Numbers + KeyEvent.VK_0 -> Key.Digit0, + KeyEvent.VK_1 -> Key.Digit1, + KeyEvent.VK_2 -> Key.Digit2, + KeyEvent.VK_3 -> Key.Digit3, + KeyEvent.VK_4 -> Key.Digit4, + KeyEvent.VK_5 -> Key.Digit5, + KeyEvent.VK_6 -> Key.Digit6, + KeyEvent.VK_7 -> Key.Digit7, + KeyEvent.VK_8 -> Key.Digit8, + KeyEvent.VK_9 -> Key.Digit9, + // Numpad Numbers + KeyEvent.VK_NUMPAD0 -> Key.NumPad0, + KeyEvent.VK_NUMPAD1 -> Key.NumPad1, + KeyEvent.VK_NUMPAD2 -> Key.NumPad2, + KeyEvent.VK_NUMPAD3 -> Key.NumPad3, + KeyEvent.VK_NUMPAD4 -> Key.NumPad4, + KeyEvent.VK_NUMPAD5 -> Key.NumPad5, + KeyEvent.VK_NUMPAD6 -> Key.NumPad6, + KeyEvent.VK_NUMPAD7 -> Key.NumPad7, + KeyEvent.VK_NUMPAD8 -> Key.NumPad8, + KeyEvent.VK_NUMPAD9 -> Key.NumPad9, + // Whitespace KeyEvent.VK_SPACE -> Key.Space, KeyEvent.VK_TAB -> Key.Tab, KeyEvent.VK_ENTER -> Key.Enter, KeyEvent.VK_BACK_SPACE -> Key.Backspace, - KeyEvent.VK_SHIFT -> Key.Shift, - KeyEvent.VK_CONTROL -> Key.Ctrl, - KeyEvent.VK_ALT -> Key.Alt, - KeyEvent.VK_META -> Key.Meta, - KeyEvent.VK_WINDOWS -> Key.Meta, - KeyEvent.VK_UP -> Key.Up, - KeyEvent.VK_DOWN -> Key.Down, - KeyEvent.VK_LEFT -> Key.Left, - KeyEvent.VK_RIGHT -> Key.Right + // Control + KeyEvent.VK_ESCAPE -> Key.Escape, + KeyEvent.VK_SHIFT -> Key.Shift, + KeyEvent.VK_CONTROL -> Key.Ctrl, + KeyEvent.VK_ALT -> Key.Alt, + KeyEvent.VK_META -> Key.Meta, + KeyEvent.VK_WINDOWS -> Key.Meta, + // Arrows + KeyEvent.VK_UP -> Key.Up, + KeyEvent.VK_DOWN -> Key.Down, + KeyEvent.VK_LEFT -> Key.Left, + KeyEvent.VK_RIGHT -> Key.Right, + // Punctuation + KeyEvent.VK_PERIOD -> Key.Period, + KeyEvent.VK_DECIMAL -> Key.Period, + KeyEvent.VK_COLON -> Key.Colon, + KeyEvent.VK_COMMA -> Key.Comma, + KeyEvent.VK_SEMICOLON -> Key.Semicolon, + KeyEvent.VK_EXCLAMATION_MARK -> Key.ExclamationMark, + // Quotes + KeyEvent.VK_QUOTE -> Key.SingleQuote, + KeyEvent.VK_QUOTEDBL -> Key.DoubleQuote, + // Slashes + KeyEvent.VK_SLASH -> Key.Slash, + KeyEvent.VK_DIVIDE -> Key.Slash, + KeyEvent.VK_BACK_SLASH -> Key.Backslash, + KeyEvent.VK_UNDERSCORE -> Key.Underscore, + // Math + KeyEvent.VK_PLUS -> Key.Plus, + KeyEvent.VK_ADD -> Key.Plus, + KeyEvent.VK_MINUS -> Key.Minus, + KeyEvent.VK_SUBTRACT -> Key.Minus, + KeyEvent.VK_ASTERISK -> Key.Asterisk, + KeyEvent.VK_MULTIPLY -> Key.Asterisk, + KeyEvent.VK_EQUALS -> Key.Equals, + // Brackets + KeyEvent.VK_LEFT_PARENTHESIS -> Key.OpenParenthesis, + KeyEvent.VK_RIGHT_PARENTHESIS -> Key.CloseParenthesis, + // Other + KeyEvent.VK_AMPERSAND -> Key.Ampersand, + KeyEvent.VK_DOLLAR -> Key.DollarSign, + KeyEvent.VK_AT -> Key.At ) } diff --git a/backend/native/src/main/scala/eu/joaocosta/minart/backend/SdlKeyMapping.scala b/backend/native/src/main/scala/eu/joaocosta/minart/backend/SdlKeyMapping.scala index 5dcc0ced..8f66744d 100644 --- a/backend/native/src/main/scala/eu/joaocosta/minart/backend/SdlKeyMapping.scala +++ b/backend/native/src/main/scala/eu/joaocosta/minart/backend/SdlKeyMapping.scala @@ -92,24 +92,23 @@ object SdlKeyMapping extends KeyMapping[SDL_KeyCode] { SDLK_SEMICOLON -> Key.Semicolon, SDLK_EXCLAIM -> Key.ExclamationMark, SDLK_KP_EXCLAM -> Key.ExclamationMark, - SDLK_QUESTION -> Key.QuestionMark, // Quotes SDLK_QUOTE -> Key.SingleQuote, SDLK_QUOTEDBL -> Key.DoubleQuote, // Slashes - SDLK_SLASH -> Key.Slash, - SDLK_KP_DIVIDE -> Key.Slash, - SDLK_BACKSLASH -> Key.Backslash, - SDLK_KP_VERTICALBAR -> Key.VerticalBar, - SDLK_UNDERSCORE -> Key.Underscore, + SDLK_SLASH -> Key.Slash, + SDLK_KP_DIVIDE -> Key.Slash, + SDLK_BACKSLASH -> Key.Backslash, + SDLK_UNDERSCORE -> Key.Underscore, // Math - SDLK_PLUS -> Key.Plus, - SDLK_KP_PLUS -> Key.Plus, - SDLK_MINUS -> Key.Minus, - SDLK_KP_MINUS -> Key.Minus, - SDLK_ASTERISK -> Key.Asterisk, - SDLK_EQUALS -> Key.Equals, - SDLK_KP_EQUALS -> Key.Equals, + SDLK_PLUS -> Key.Plus, + SDLK_KP_PLUS -> Key.Plus, + SDLK_MINUS -> Key.Minus, + SDLK_KP_MINUS -> Key.Minus, + SDLK_ASTERISK -> Key.Asterisk, + SDLK_KP_MULTIPLY -> Key.Asterisk, + SDLK_EQUALS -> Key.Equals, + SDLK_KP_EQUALS -> Key.Equals, // Brackets SDLK_LEFTPAREN -> Key.OpenParenthesis, SDLK_KP_LEFTPAREN -> Key.OpenParenthesis, diff --git a/core/shared/src/main/scala/eu/joaocosta/minart/input/KeyboardInput.scala b/core/shared/src/main/scala/eu/joaocosta/minart/input/KeyboardInput.scala index e2835cb1..6a501434 100644 --- a/core/shared/src/main/scala/eu/joaocosta/minart/input/KeyboardInput.scala +++ b/core/shared/src/main/scala/eu/joaocosta/minart/input/KeyboardInput.scala @@ -158,7 +158,6 @@ object KeyboardInput { case Comma case Semicolon case ExclamationMark - case QuestionMark // Quotes case SingleQuote @@ -167,7 +166,6 @@ object KeyboardInput { // Slashes case Slash case Backslash - case VerticalBar case Underscore // Math From 237cbfc1b768a900cfdd484d53c15a97305ff727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Costa?= Date: Sun, 19 Nov 2023 19:49:35 +0100 Subject: [PATCH 3/4] Add more JS key mappings --- .../minart/backend/JsKeyMapping.scala | 119 +++++++++++------- 1 file changed, 75 insertions(+), 44 deletions(-) diff --git a/backend/js/src/main/scala/eu/joaocosta/minart/backend/JsKeyMapping.scala b/backend/js/src/main/scala/eu/joaocosta/minart/backend/JsKeyMapping.scala index 916f42d8..456a231b 100644 --- a/backend/js/src/main/scala/eu/joaocosta/minart/backend/JsKeyMapping.scala +++ b/backend/js/src/main/scala/eu/joaocosta/minart/backend/JsKeyMapping.scala @@ -6,42 +6,45 @@ import eu.joaocosta.minart.input.KeyboardInput.* */ object JsKeyMapping extends KeyMapping[Int] { protected val mappings: Map[Int, Key] = Map( - 65 -> Key.A, - 66 -> Key.B, - 67 -> Key.C, - 68 -> Key.D, - 69 -> Key.E, - 70 -> Key.F, - 71 -> Key.G, - 72 -> Key.H, - 73 -> Key.I, - 74 -> Key.J, - 75 -> Key.K, - 76 -> Key.L, - 77 -> Key.M, - 78 -> Key.N, - 79 -> Key.O, - 80 -> Key.P, - 81 -> Key.Q, - 82 -> Key.R, - 83 -> Key.S, - 84 -> Key.T, - 85 -> Key.U, - 86 -> Key.V, - 87 -> Key.W, - 88 -> Key.X, - 89 -> Key.Y, - 90 -> Key.Z, - 48 -> Key.Digit0, - 49 -> Key.Digit1, - 50 -> Key.Digit2, - 51 -> Key.Digit3, - 52 -> Key.Digit4, - 53 -> Key.Digit5, - 54 -> Key.Digit6, - 55 -> Key.Digit7, - 56 -> Key.Digit8, - 57 -> Key.Digit9, + // Letters + 65 -> Key.A, + 66 -> Key.B, + 67 -> Key.C, + 68 -> Key.D, + 69 -> Key.E, + 70 -> Key.F, + 71 -> Key.G, + 72 -> Key.H, + 73 -> Key.I, + 74 -> Key.J, + 75 -> Key.K, + 76 -> Key.L, + 77 -> Key.M, + 78 -> Key.N, + 79 -> Key.O, + 80 -> Key.P, + 81 -> Key.Q, + 82 -> Key.R, + 83 -> Key.S, + 84 -> Key.T, + 85 -> Key.U, + 86 -> Key.V, + 87 -> Key.W, + 88 -> Key.X, + 89 -> Key.Y, + 90 -> Key.Z, + // Numbers + 48 -> Key.Digit0, + 49 -> Key.Digit1, + 50 -> Key.Digit2, + 51 -> Key.Digit3, + 52 -> Key.Digit4, + 53 -> Key.Digit5, + 54 -> Key.Digit6, + 55 -> Key.Digit7, + 56 -> Key.Digit8, + 57 -> Key.Digit9, + // Numpad Numbers 96 -> Key.NumPad0, 97 -> Key.NumPad1, 98 -> Key.NumPad2, @@ -52,18 +55,46 @@ object JsKeyMapping extends KeyMapping[Int] { 103 -> Key.NumPad7, 104 -> Key.NumPad8, 105 -> Key.NumPad9, - 32 -> Key.Space, - 9 -> Key.Tab, - 13 -> Key.Enter, - 8 -> Key.Backspace, + // Whitespace + 32 -> Key.Space, + 9 -> Key.Tab, + 13 -> Key.Enter, + 8 -> Key.Backspace, + // Control 27 -> Key.Escape, 16 -> Key.Shift, 17 -> Key.Ctrl, 18 -> Key.Alt, 224 -> Key.Meta, - 38 -> Key.Up, - 40 -> Key.Down, - 37 -> Key.Left, - 39 -> Key.Right + // Arrows + 38 -> Key.Up, + 40 -> Key.Down, + 37 -> Key.Left, + 39 -> Key.Right, + // Punctuation + 190 -> Key.Period, + 58 -> Key.Colon, + 189 -> Key.Comma, + 59 -> Key.Semicolon, + 161 -> Key.ExclamationMark, + // Quotes + 222 -> Key.SingleQuote, + 162 -> Key.DoubleQuote, + // Slashes + 191 -> Key.Slash, + 220 -> Key.Backslash, + 167 -> Key.Underscore, + // Math + 171 -> Key.Plus, + 173 -> Key.Minus, + 170 -> Key.Asterisk, + 61 -> Key.Equals, + // Brackets + 168 -> Key.OpenParenthesis, + 169 -> Key.CloseParenthesis, + // Other + 166 -> Key.Ampersand, + 164 -> Key.DollarSign, + 64 -> Key.At ) } From 6b94a3a7b060fb51260cf8c91b2426265089c9bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Costa?= Date: Sun, 19 Nov 2023 20:25:24 +0100 Subject: [PATCH 4/4] Add Key#baseChar --- .../minart/input/KeyboardInput.scala | 161 +++++++++--------- 1 file changed, 82 insertions(+), 79 deletions(-) diff --git a/core/shared/src/main/scala/eu/joaocosta/minart/input/KeyboardInput.scala b/core/shared/src/main/scala/eu/joaocosta/minart/input/KeyboardInput.scala index 6a501434..dfbf89ef 100644 --- a/core/shared/src/main/scala/eu/joaocosta/minart/input/KeyboardInput.scala +++ b/core/shared/src/main/scala/eu/joaocosta/minart/input/KeyboardInput.scala @@ -79,108 +79,111 @@ object KeyboardInput { } /** Platform-agnostic identifier for a keyboard key. + * + * Has a `baseChar` value with an optional char, + * which represents the key with no modifiers. */ - enum Key { + enum Key(val baseChar: Option[Char]) { // Letters - case A - case B - case C - case D - case E - case F - case G - case H - case I - case J - case K - case L - case M - case N - case O - case P - case Q - case R - case S - case T - case U - case V - case W - case X - case Y - case Z + case A extends Key(Some('a')) + case B extends Key(Some('b')) + case C extends Key(Some('c')) + case D extends Key(Some('d')) + case E extends Key(Some('e')) + case F extends Key(Some('f')) + case G extends Key(Some('g')) + case H extends Key(Some('h')) + case I extends Key(Some('i')) + case J extends Key(Some('j')) + case K extends Key(Some('k')) + case L extends Key(Some('l')) + case M extends Key(Some('m')) + case N extends Key(Some('n')) + case O extends Key(Some('o')) + case P extends Key(Some('p')) + case Q extends Key(Some('q')) + case R extends Key(Some('r')) + case S extends Key(Some('s')) + case T extends Key(Some('t')) + case U extends Key(Some('u')) + case V extends Key(Some('v')) + case W extends Key(Some('w')) + case X extends Key(Some('x')) + case Y extends Key(Some('y')) + case Z extends Key(Some('z')) // Numbers - case Digit0 - case Digit1 - case Digit2 - case Digit3 - case Digit4 - case Digit5 - case Digit6 - case Digit7 - case Digit8 - case Digit9 + case Digit0 extends Key(Some('0')) + case Digit1 extends Key(Some('1')) + case Digit2 extends Key(Some('2')) + case Digit3 extends Key(Some('3')) + case Digit4 extends Key(Some('4')) + case Digit5 extends Key(Some('5')) + case Digit6 extends Key(Some('6')) + case Digit7 extends Key(Some('7')) + case Digit8 extends Key(Some('8')) + case Digit9 extends Key(Some('9')) // Numpad Numbers - case NumPad0 - case NumPad1 - case NumPad2 - case NumPad3 - case NumPad4 - case NumPad5 - case NumPad6 - case NumPad7 - case NumPad8 - case NumPad9 + case NumPad0 extends Key(Some('0')) + case NumPad1 extends Key(Some('1')) + case NumPad2 extends Key(Some('2')) + case NumPad3 extends Key(Some('3')) + case NumPad4 extends Key(Some('4')) + case NumPad5 extends Key(Some('5')) + case NumPad6 extends Key(Some('6')) + case NumPad7 extends Key(Some('7')) + case NumPad8 extends Key(Some('8')) + case NumPad9 extends Key(Some('9')) // Whitespace - case Space - case Tab - case Enter - case Backspace + case Space extends Key(Some(' ')) + case Tab extends Key(Some('\t')) + case Enter extends Key(Some('\r')) + case Backspace extends Key(Some('\u0008')) // Control - case Escape - case Shift - case Ctrl - case Alt - case Meta + case Escape extends Key(None) + case Shift extends Key(None) + case Ctrl extends Key(None) + case Alt extends Key(None) + case Meta extends Key(None) // Arrows - case Up - case Down - case Left - case Right + case Up extends Key(None) + case Down extends Key(None) + case Left extends Key(None) + case Right extends Key(None) // Punctuation - case Period - case Colon - case Comma - case Semicolon - case ExclamationMark + case Period extends Key(Some('.')) + case Colon extends Key(Some(':')) + case Comma extends Key(Some(',')) + case Semicolon extends Key(Some(';')) + case ExclamationMark extends Key(Some('!')) // Quotes - case SingleQuote - case DoubleQuote + case SingleQuote extends Key(Some('\'')) + case DoubleQuote extends Key(Some('"')) // Slashes - case Slash - case Backslash - case Underscore + case Slash extends Key(Some('/')) + case Backslash extends Key(Some('\\')) + case Underscore extends Key(Some('_')) // Math - case Plus - case Minus - case Asterisk - case Equals + case Plus extends Key(Some('+')) + case Minus extends Key(Some('-')) + case Asterisk extends Key(Some('*')) + case Equals extends Key(Some('=')) // Brackets - case OpenParenthesis - case CloseParenthesis + case OpenParenthesis extends Key(Some('(')) + case CloseParenthesis extends Key(Some(')')) // Other - case Ampersand - case DollarSign - case At + case Ampersand extends Key(Some('&')) + case DollarSign extends Key(Some('$')) + case At extends Key(Some('@')) } }