diff --git a/src/cs/MonoGame.Extended.Input/KeyboardStateExtended.cs b/src/cs/MonoGame.Extended.Input/KeyboardStateExtended.cs
index 591aaf5e..ee186771 100644
--- a/src/cs/MonoGame.Extended.Input/KeyboardStateExtended.cs
+++ b/src/cs/MonoGame.Extended.Input/KeyboardStateExtended.cs
@@ -1,4 +1,5 @@
-using System.Linq;
+using System;
+using System.Linq;
using Microsoft.Xna.Framework.Input;
namespace MonoGame.Extended.Input
@@ -23,8 +24,37 @@ namespace MonoGame.Extended.Input
public bool IsKeyUp(Keys key) => _currentKeyboardState.IsKeyUp(key);
public Keys[] GetPressedKeys() => _currentKeyboardState.GetPressedKeys();
public void GetPressedKeys(Keys[] keys) => _currentKeyboardState.GetPressedKeys(keys);
+
+ ///
+ /// Gets whether the given key was down on the previous state, but is now up.
+ ///
+ /// The key to check.
+ /// true if the key was released this state-change, otherwise false.
+ [Obsolete($"Deprecated in favor of {nameof(IsKeyReleased)}")]
public bool WasKeyJustDown(Keys key) => _previousKeyboardState.IsKeyDown(key) && _currentKeyboardState.IsKeyUp(key);
+
+ ///
+ /// Gets whether the given key was up on the previous state, but is now down.
+ ///
+ /// The key to check.
+ /// true if the key was pressed this state-change, otherwise false.
+ [Obsolete($"Deprecated in favor of {nameof(IsKeyPressed)}")]
public bool WasKeyJustUp(Keys key) => _previousKeyboardState.IsKeyUp(key) && _currentKeyboardState.IsKeyDown(key);
+
+ ///
+ /// Gets whether the given key was down on the previous state, but is now up.
+ ///
+ /// The key to check.
+ /// true if the key was released this state-change, otherwise false.
+ public readonly bool IsKeyReleased(Keys key) => _previousKeyboardState.IsKeyDown(key) && _currentKeyboardState.IsKeyUp(key);
+
+ ///
+ /// Gets whether the given key was up on the previous state, but is now down.
+ ///
+ /// The key to check.
+ /// true if the key was pressed this state-change, otherwise false.
+ public readonly bool IsKeyPressed(Keys key) => _previousKeyboardState.IsKeyUp(key) && _currentKeyboardState.IsKeyDown(key);
+
public bool WasAnyKeyJustDown() => _previousKeyboardState.GetPressedKeyCount() > 0;
}
}
diff --git a/src/cs/MonoGame.Extended.Input/MouseStateExtended.cs b/src/cs/MonoGame.Extended.Input/MouseStateExtended.cs
index d9379d83..0ec6943f 100644
--- a/src/cs/MonoGame.Extended.Input/MouseStateExtended.cs
+++ b/src/cs/MonoGame.Extended.Input/MouseStateExtended.cs
@@ -63,6 +63,13 @@ namespace MonoGame.Extended.Input
return false;
}
+ ///
+ /// Get the just-down state for the mouse on this state-change: true if the mouse button has just been pressed.
+ ///
+ ///
+ /// Deprecated because of inconsistency with
+ /// The just-down state for the mouse on this state-change.
+ [Obsolete($"Deprecated in favor of {nameof(IsButtonPressed)}")]
public bool WasButtonJustDown(MouseButton button)
{
// ReSharper disable once SwitchStatementMissingSomeCases
@@ -78,6 +85,13 @@ namespace MonoGame.Extended.Input
return false;
}
+ ///
+ /// Get the just-up state for the mouse on this state-change: true if the mouse button has just been released.
+ ///
+ ///
+ /// Deprecated because of inconsistency with
+ /// The just-up state for the mouse on this state-change.
+ [Obsolete($"Deprecated in favor of {nameof(IsButtonReleased)}")]
public bool WasButtonJustUp(MouseButton button)
{
// ReSharper disable once SwitchStatementMissingSomeCases
@@ -93,9 +107,43 @@ namespace MonoGame.Extended.Input
return false;
}
- private bool IsPressed(Func button) => button(_currentMouseState) == ButtonState.Pressed;
- private bool IsReleased(Func button) => button(_currentMouseState) == ButtonState.Released;
- private bool WasJustPressed(Func button) => button(_previousMouseState) == ButtonState.Released && button(_currentMouseState) == ButtonState.Pressed;
- private bool WasJustReleased(Func button) => button(_previousMouseState) == ButtonState.Pressed && button(_currentMouseState) == ButtonState.Released;
+ ///
+ /// Get the pressed state of a mouse button, for this state-change.
+ ///
+ /// The button to check.
+ /// true if the given mouse button was pressed this state-change, otherwise false
+ public readonly bool IsButtonPressed(MouseButton button) => button switch
+ {
+ MouseButton.Left => WasJustPressed(m => m.LeftButton),
+ MouseButton.Middle => WasJustPressed(m => m.MiddleButton),
+ MouseButton.Right => WasJustPressed(m => m.RightButton),
+ MouseButton.XButton1 => WasJustPressed(m => m.XButton1),
+ MouseButton.XButton2 => WasJustPressed(m => m.XButton2),
+ _ => false,
+ };
+
+ ///
+ /// Get the released state of a mouse button, for this state-change.
+ ///
+ /// The button to check.
+ /// true if the given mouse button was released this state-change, otherwise false
+ public readonly bool IsButtonReleased(MouseButton button) => button switch
+ {
+ MouseButton.Left => WasJustReleased(m => m.LeftButton),
+ MouseButton.Middle => WasJustReleased(m => m.MiddleButton),
+ MouseButton.Right => WasJustReleased(m => m.RightButton),
+ MouseButton.XButton1 => WasJustReleased(m => m.XButton1),
+ MouseButton.XButton2 => WasJustReleased(m => m.XButton2),
+ _ => false,
+ };
+
+ private readonly bool IsPressed(Func button)
+ => button(_currentMouseState) == ButtonState.Pressed;
+ private readonly bool IsReleased(Func button)
+ => button(_currentMouseState) == ButtonState.Released;
+ private readonly bool WasJustPressed(Func button)
+ => button(_previousMouseState) == ButtonState.Released && button(_currentMouseState) == ButtonState.Pressed;
+ private readonly bool WasJustReleased(Func button)
+ => button(_previousMouseState) == ButtonState.Pressed && button(_currentMouseState) == ButtonState.Released;
}
-}
\ No newline at end of file
+}