forked from craftworkgames/MonoGame.Extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyboardStateExtended.cs
30 lines (26 loc) · 1.59 KB
/
KeyboardStateExtended.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System.Linq;
using Microsoft.Xna.Framework.Input;
namespace MonoGame.Extended.Input
{
public struct KeyboardStateExtended
{
private KeyboardState _currentKeyboardState;
private KeyboardState _previousKeyboardState;
public KeyboardStateExtended(KeyboardState currentKeyboardState, KeyboardState previousKeyboardState)
{
_currentKeyboardState = currentKeyboardState;
_previousKeyboardState = previousKeyboardState;
}
public bool CapsLock => _currentKeyboardState.CapsLock;
public bool NumLock => _currentKeyboardState.NumLock;
public bool IsShiftDown() => _currentKeyboardState.IsKeyDown(Keys.LeftShift) || _currentKeyboardState.IsKeyDown(Keys.RightShift);
public bool IsControlDown() => _currentKeyboardState.IsKeyDown(Keys.LeftControl) || _currentKeyboardState.IsKeyDown(Keys.RightControl);
public bool IsAltDown() => _currentKeyboardState.IsKeyDown(Keys.LeftAlt) || _currentKeyboardState.IsKeyDown(Keys.RightAlt);
public bool IsKeyDown(Keys key) => _currentKeyboardState.IsKeyDown(key);
public bool IsKeyUp(Keys key) => _currentKeyboardState.IsKeyUp(key);
public Keys[] GetPressedKeys() => _currentKeyboardState.GetPressedKeys();
public bool WasKeyJustDown(Keys key) => _previousKeyboardState.IsKeyDown(key) && _currentKeyboardState.IsKeyUp(key);
public bool WasKeyJustUp(Keys key) => _previousKeyboardState.IsKeyUp(key) && _currentKeyboardState.IsKeyDown(key);
public bool WasAnyKeyJustDown() => _previousKeyboardState.GetPressedKeys().Any();
}
}