From ade4d73abc23bf3e363c22908082214503605b44 Mon Sep 17 00:00:00 2001 From: JamesOrson Date: Thu, 9 Jul 2020 21:16:07 -0700 Subject: [PATCH] Add missing keyboard inputs --- Komodo/Core/Engine/Input/InputManager.cs | 7 +- Komodo/Core/Engine/Input/InputMapper.cs | 83 +++++++++++++++++++++++- Komodo/Core/Engine/Input/Inputs.cs | 36 ++++++++++ 3 files changed, 120 insertions(+), 6 deletions(-) diff --git a/Komodo/Core/Engine/Input/InputManager.cs b/Komodo/Core/Engine/Input/InputManager.cs index 98e86c67..7fada3a7 100644 --- a/Komodo/Core/Engine/Input/InputManager.cs +++ b/Komodo/Core/Engine/Input/InputManager.cs @@ -8,6 +8,7 @@ using GamePadState = Microsoft.Xna.Framework.Input.GamePadState; using Keyboard = Microsoft.Xna.Framework.Input.Keyboard; using KeyboardState = Microsoft.Xna.Framework.Input.KeyboardState; +using Keys = Microsoft.Xna.Framework.Input.Keys; using Mouse = Microsoft.Xna.Framework.Input.Mouse; using MouseState = Microsoft.Xna.Framework.Input.MouseState; @@ -291,7 +292,7 @@ internal static void Update() #region Static Methods /// - /// Retrives for the given . + /// Retrieves for the given . /// /// Identifier for the device input to query. /// Identifier for the player to query. @@ -348,9 +349,9 @@ private static InputInfo GetInputInfo(Inputs input, int playerIndex = 0, bool us } var monogameKeyInput = InputMapper.ToMonoGameKey(input); - if (monogameKeyInput.HasValue) + if (monogameKeyInput != Keys.None) { - bool isDown = keyboardState.IsKeyDown(monogameKeyInput.Value); + bool isDown = keyboardState.IsKeyDown(monogameKeyInput); komodoInputState = isDown ? InputState.Down : InputState.Up; } diff --git a/Komodo/Core/Engine/Input/InputMapper.cs b/Komodo/Core/Engine/Input/InputMapper.cs index 705c8031..09196f94 100644 --- a/Komodo/Core/Engine/Input/InputMapper.cs +++ b/Komodo/Core/Engine/Input/InputMapper.cs @@ -1,3 +1,6 @@ +using Microsoft.Xna.Framework.Input; +using System.Diagnostics; +using System.Runtime.InteropServices; using Buttons = Microsoft.Xna.Framework.Input.Buttons; using ButtonState = Microsoft.Xna.Framework.Input.ButtonState; using Keys = Microsoft.Xna.Framework.Input.Keys; @@ -53,13 +56,25 @@ internal static Inputs ToInputs(Keys key) return key switch { Keys.A => Inputs.KeyA, + Keys.Add => Inputs.KeyAdd, Keys.B => Inputs.KeyB, Keys.Back => Inputs.KeyBackSpace, Keys.C => Inputs.KeyC, Keys.CapsLock => Inputs.KeyCapsLock, Keys.D => Inputs.KeyD, + Keys.D0 => Inputs.Key0, + Keys.D1 => Inputs.Key1, + Keys.D2 => Inputs.Key2, + Keys.D3 => Inputs.Key3, + Keys.D4 => Inputs.Key4, + Keys.D5 => Inputs.Key5, + Keys.D6 => Inputs.Key6, + Keys.D7 => Inputs.Key7, + Keys.D8 => Inputs.Key8, + Keys.D9 => Inputs.Key9, Keys.Decimal => Inputs.KeyDecimal, Keys.Delete => Inputs.KeyDelete, + Keys.Divide => Inputs.KeyDivide, Keys.Down => Inputs.KeyDown, Keys.E => Inputs.KeyE, Keys.Enter => Inputs.KeyEnter, @@ -88,8 +103,31 @@ internal static Inputs ToInputs(Keys key) Keys.LeftControl => Inputs.KeyLeftControl, Keys.LeftShift => Inputs.KeyLeftShift, Keys.M => Inputs.KeyM, + Keys.Multiply => Inputs.KeyMultiply, Keys.N => Inputs.KeyN, + Keys.NumPad0 => Inputs.KeyNumPad0, + Keys.NumPad1 => Inputs.KeyNumPad1, + Keys.NumPad2 => Inputs.KeyNumPad2, + Keys.NumPad3 => Inputs.KeyNumPad3, + Keys.NumPad4 => Inputs.KeyNumPad4, + Keys.NumPad5 => Inputs.KeyNumPad5, + Keys.NumPad6 => Inputs.KeyNumPad6, + Keys.NumPad7 => Inputs.KeyNumPad7, + Keys.NumPad8 => Inputs.KeyNumPad8, + Keys.NumPad9 => Inputs.KeyNumPad9, Keys.O => Inputs.KeyO, + Keys.OemBackslash => Inputs.KeyBackslash, + Keys.OemCloseBrackets => Inputs.KeyCloseBrackets, + Keys.OemComma => Inputs.KeyComma, + Keys.OemMinus => Inputs.KeyMinus, + Keys.OemOpenBrackets => Inputs.KeyOpenBrackets, + Keys.OemPeriod => Inputs.KeyPeriod, + Keys.OemPipe => Inputs.KeyBackslash, + Keys.OemPlus => Inputs.KeyPlus, + Keys.OemQuestion => Inputs.KeyQuestion, + Keys.OemQuotes => Inputs.KeyQuotes, + Keys.OemSemicolon => Inputs.KeySemicolon, + Keys.OemTilde => Inputs.KeyTilde, Keys.P => Inputs.KeyP, Keys.Q => Inputs.KeyQ, Keys.R => Inputs.KeyR, @@ -98,6 +136,8 @@ internal static Inputs ToInputs(Keys key) Keys.RightControl => Inputs.KeyRightControl, Keys.RightShift => Inputs.KeyRightShift, Keys.S => Inputs.KeyS, + Keys.Space => Inputs.KeySpace, + Keys.Subtract => Inputs.KeySubtract, Keys.T => Inputs.KeyT, Keys.Tab => Inputs.KeyTab, Keys.U => Inputs.KeyU, @@ -176,18 +216,33 @@ internal static InputState ToInputState(KeyState keyState) /// /// Komodo input. /// Converted Komodo input as . - internal static Keys? ToMonoGameKey(Inputs input) + internal static Keys ToMonoGameKey(Inputs input) { - return input switch + var result = input switch { + Inputs.Key0 => Keys.D0, + Inputs.Key1 => Keys.D1, + Inputs.Key2 => Keys.D2, + Inputs.Key3 => Keys.D3, + Inputs.Key4 => Keys.D4, + Inputs.Key5 => Keys.D5, + Inputs.Key6 => Keys.D6, + Inputs.Key7 => Keys.D7, + Inputs.Key8 => Keys.D8, + Inputs.Key9 => Keys.D9, Inputs.KeyA => Keys.A, + Inputs.KeyAdd => Keys.Add, Inputs.KeyB => Keys.B, Inputs.KeyBackSpace => Keys.Back, + Inputs.KeyBackslash => Keys.OemPipe, Inputs.KeyC => Keys.C, Inputs.KeyCapsLock => Keys.CapsLock, + Inputs.KeyCloseBrackets => Keys.OemCloseBrackets, + Inputs.KeyComma => Keys.OemComma, Inputs.KeyD => Keys.D, Inputs.KeyDecimal => Keys.Decimal, Inputs.KeyDelete => Keys.Delete, + Inputs.KeyDivide => Keys.Divide, Inputs.KeyDown => Keys.Down, Inputs.KeyE => Keys.E, Inputs.KeyEnter => Keys.Enter, @@ -216,18 +271,39 @@ internal static InputState ToInputState(KeyState keyState) Inputs.KeyLeftControl => Keys.LeftControl, Inputs.KeyLeftShift => Keys.LeftShift, Inputs.KeyM => Keys.M, + Inputs.KeyMinus => Keys.OemMinus, + Inputs.KeyMultiply => Keys.Multiply, Inputs.KeyN => Keys.N, + Inputs.KeyNumPad0 => Keys.NumPad0, + Inputs.KeyNumPad1 => Keys.NumPad1, + Inputs.KeyNumPad2 => Keys.NumPad2, + Inputs.KeyNumPad3 => Keys.NumPad3, + Inputs.KeyNumPad4 => Keys.NumPad4, + Inputs.KeyNumPad5 => Keys.NumPad5, + Inputs.KeyNumPad6 => Keys.NumPad6, + Inputs.KeyNumPad7 => Keys.NumPad7, + Inputs.KeyNumPad8 => Keys.NumPad8, + Inputs.KeyNumPad9 => Keys.NumPad9, Inputs.KeyO => Keys.O, + Inputs.KeyOpenBrackets => Keys.OemOpenBrackets, Inputs.KeyP => Keys.P, + Inputs.KeyPeriod => Keys.OemPeriod, + Inputs.KeyPlus => Keys.OemPlus, Inputs.KeyQ => Keys.Q, + Inputs.KeyQuestion => Keys.OemQuestion, + Inputs.KeyQuotes => Keys.OemQuotes, Inputs.KeyR => Keys.R, Inputs.KeyRight => Keys.Right, Inputs.KeyRightAlt => Keys.RightAlt, Inputs.KeyRightControl => Keys.RightControl, Inputs.KeyRightShift => Keys.RightShift, Inputs.KeyS => Keys.S, + Inputs.KeySemicolon => Keys.OemSemicolon, + Inputs.KeySpace => Keys.Space, + Inputs.KeySubtract => Keys.Subtract, Inputs.KeyT => Keys.T, Inputs.KeyTab => Keys.Tab, + Inputs.KeyTilde => Keys.OemTilde, Inputs.KeyU => Keys.U, Inputs.KeyUp => Keys.Up, Inputs.KeyV => Keys.V, @@ -235,8 +311,9 @@ internal static InputState ToInputState(KeyState keyState) Inputs.KeyX => Keys.X, Inputs.KeyY => Keys.Y, Inputs.KeyZ => Keys.Z, - _ => null, + _ => Keys.None, }; + return result; } #endregion diff --git a/Komodo/Core/Engine/Input/Inputs.cs b/Komodo/Core/Engine/Input/Inputs.cs index d383aea1..921a3124 100644 --- a/Komodo/Core/Engine/Input/Inputs.cs +++ b/Komodo/Core/Engine/Input/Inputs.cs @@ -27,14 +27,29 @@ public enum Inputs ThumbstickLeft, ThumbstickRight, // Keys + Key0, + Key1, + Key2, + Key3, + Key4, + Key5, + Key6, + Key7, + Key8, + Key9, KeyA, + KeyAdd, KeyB, KeyBackSpace, + KeyBackslash, KeyC, KeyCapsLock, + KeyCloseBrackets, + KeyComma, KeyD, KeyDecimal, KeyDelete, + KeyDivide, KeyDown, KeyE, KeyEnter, @@ -63,18 +78,39 @@ public enum Inputs KeyLeftControl, KeyLeftShift, KeyM, + KeyMinus, + KeyMultiply, KeyN, + KeyNumPad0, + KeyNumPad1, + KeyNumPad2, + KeyNumPad3, + KeyNumPad4, + KeyNumPad5, + KeyNumPad6, + KeyNumPad7, + KeyNumPad8, + KeyNumPad9, KeyO, + KeyOpenBrackets, KeyP, + KeyPeriod, + KeyPlus, KeyQ, + KeyQuestion, + KeyQuotes, KeyR, KeyRight, KeyRightAlt, KeyRightControl, KeyRightShift, KeyS, + KeySemicolon, + KeySpace, + KeySubtract, KeyT, KeyTab, + KeyTilde, KeyU, KeyUp, KeyV,