Skip to content

Commit

Permalink
Add missing keyboard inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesaorson committed Jul 10, 2020
1 parent 540769a commit ade4d73
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 6 deletions.
7 changes: 4 additions & 3 deletions Komodo/Core/Engine/Input/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -291,7 +292,7 @@ internal static void Update()

#region Static Methods
/// <summary>
/// Retrives <see cref="Komodo.Core.Engine.Input.InputInfo"/> for the given <see cref="Komodo.Core.Engine.Input.Inputs"/>.
/// Retrieves <see cref="Komodo.Core.Engine.Input.InputInfo"/> for the given <see cref="Komodo.Core.Engine.Input.Inputs"/>.
/// </summary>
/// <param name="input">Identifier for the device input to query.</param>
/// <param name="playerIndex">Identifier for the player to query.</param>
Expand Down Expand Up @@ -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;
}

Expand Down
83 changes: 80 additions & 3 deletions Komodo/Core/Engine/Input/InputMapper.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -176,18 +216,33 @@ internal static InputState ToInputState(KeyState keyState)
/// </summary>
/// <param name="input">Komodo input.</param>
/// <returns>Converted Komodo input as <see cref="Microsoft.Xna.Framework.Input.Keys"/>.</returns>
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,
Expand Down Expand Up @@ -216,27 +271,49 @@ 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,
Inputs.KeyW => Keys.W,
Inputs.KeyX => Keys.X,
Inputs.KeyY => Keys.Y,
Inputs.KeyZ => Keys.Z,
_ => null,
_ => Keys.None,
};
return result;
}
#endregion

Expand Down
36 changes: 36 additions & 0 deletions Komodo/Core/Engine/Input/Inputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ade4d73

Please sign in to comment.