Added missing summeries #1
This commit is contained in:
parent
03d99ea28e
commit
8665b5b709
104 changed files with 1165 additions and 821 deletions
|
|
@ -1,18 +1,24 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Forms;
|
||||
using OpenTK.Input;
|
||||
using SharpDX.Win32;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Controls
|
||||
{
|
||||
public class Keyboard
|
||||
/// <summary>
|
||||
/// A static class to get keyboard inputs.
|
||||
/// </summary>
|
||||
public static class Keyboard
|
||||
{
|
||||
internal static KeyboardState? _keyboardState;
|
||||
internal static List<Key> _lastPressedKeys = new List<Key>();
|
||||
|
||||
/// <summary>
|
||||
/// True, when ANY key pressed.
|
||||
/// </summary>
|
||||
public static bool IsAnyKeyPressed => _keyboardState?.IsAnyKeyDown == true;
|
||||
|
||||
|
||||
|
|
@ -23,18 +29,53 @@ namespace SM.Base.Controls
|
|||
_lastPressedKeys = new List<Key>();
|
||||
|
||||
foreach (object o in Enum.GetValues(typeof(Key)))
|
||||
{
|
||||
if (_keyboardState.Value[(Key)o]) _lastPressedKeys.Add((Key)o);
|
||||
}
|
||||
if (_keyboardState.Value[(Key) o])
|
||||
_lastPressedKeys.Add((Key) o);
|
||||
}
|
||||
|
||||
_keyboardState = OpenTK.Input.Keyboard.GetState();
|
||||
}
|
||||
|
||||
public static bool IsDown(Key key, bool once = false) => _keyboardState?[key] == true && !(once && _lastPressedKeys.Contains(key));
|
||||
public static bool WasDown(Key key) => _keyboardState?[key] == false && _lastPressedKeys.Contains(key);
|
||||
public static bool IsUp(Key key, bool once = false) => _keyboardState?[key] == false && !(once && !_lastPressedKeys.Contains(key));
|
||||
/// <summary>
|
||||
/// Checks if a key is down.
|
||||
/// </summary>
|
||||
/// <param name="key">The key</param>
|
||||
/// <param name="once">If true, the method doesn't return true, when it was pressed one stage before.</param>
|
||||
/// <returns></returns>
|
||||
public static bool IsDown(Key key, bool once = false)
|
||||
{
|
||||
return _keyboardState?[key] == true && !(once && _lastPressedKeys.Contains(key));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a key was down but not anymore.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static bool WasDown(Key key)
|
||||
{
|
||||
return _keyboardState?[key] == false && _lastPressedKeys.Contains(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a is up.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="once">If true, the method doesn't return true, when it was up one stage before.</param>
|
||||
/// <returns></returns>
|
||||
public static bool IsUp(Key key, bool once = false)
|
||||
{
|
||||
return _keyboardState?[key] == false && !(once && !_lastPressedKeys.Contains(key));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if specific keys are down.
|
||||
/// </summary>
|
||||
/// <param name="startIndex">Startindex</param>
|
||||
/// <param name="endIndex">Endindex</param>
|
||||
/// <param name="once">If true, it ignores keys that were down a state before.</param>
|
||||
/// <returns>True if any of the specific keys where found down.</returns>
|
||||
/// <exception cref="ArgumentException">The start index can't be greater then the end index.</exception>
|
||||
public static bool AreSpecificKeysPressed(int startIndex, int endIndex, bool once = false)
|
||||
{
|
||||
if (startIndex > endIndex)
|
||||
|
|
@ -51,19 +92,42 @@ namespace SM.Base.Controls
|
|||
return false;
|
||||
}
|
||||
|
||||
public static bool AreSpecificKeysPressed(params Key[] keys) => AreSpecificKeysPressed(false, keys);
|
||||
/// <summary>
|
||||
/// Checks if any of the specific keys are pressed.
|
||||
/// </summary>
|
||||
/// <param name="keys"></param>
|
||||
/// <returns></returns>
|
||||
public static bool AreSpecificKeysPressed(params Key[] keys)
|
||||
{
|
||||
return AreSpecificKeysPressed(false, keys);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if any of the specific keys are pressed.
|
||||
/// </summary>
|
||||
/// <param name="once">If true, it ignores keys that were down a state before.</param>
|
||||
/// <param name="keys"></param>
|
||||
/// <returns></returns>
|
||||
public static bool AreSpecificKeysPressed(bool once, params Key[] keys)
|
||||
{
|
||||
foreach (Key key in keys)
|
||||
{
|
||||
if (IsDown(key, once)) return true;
|
||||
}
|
||||
if (IsDown(key, once))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool AreSpecificKeysPressed(int startIndex, int endIndex, out Key[] pressedKeys, bool once = false)
|
||||
/// <summary>
|
||||
/// Checks if specific keys are down and returns the pressed keys.
|
||||
/// </summary>
|
||||
/// <param name="startIndex">Startindex</param>
|
||||
/// <param name="endIndex">Endindex</param>
|
||||
/// <param name="pressedKeys"></param>
|
||||
/// <param name="once">If true, it ignores keys that were down a state before.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public static bool AreSpecificKeysPressed(int startIndex, int endIndex, out Key[] pressedKeys,
|
||||
bool once = false)
|
||||
{
|
||||
if (startIndex > endIndex)
|
||||
throw new ArgumentException("The startIndex is greater than the endIndex.", nameof(startIndex));
|
||||
|
|
@ -75,34 +139,47 @@ namespace SM.Base.Controls
|
|||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
int actualIndex = i + startIndex;
|
||||
Key key = (Key)actualIndex;
|
||||
Key key = (Key) actualIndex;
|
||||
if (IsDown(key, once))
|
||||
{
|
||||
keys.Add(key);
|
||||
success = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pressedKeys = keys.ToArray();
|
||||
return success;
|
||||
}
|
||||
|
||||
public static bool AreSpecificKeysPressed(out Key[] pressedKey, params Key[] keys) => AreSpecificKeysPressed(false, out pressedKey, keys);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if any of the specific keys are pressed and returns them.
|
||||
/// </summary>
|
||||
/// <param name="pressedKey"></param>
|
||||
/// <param name="keys"></param>
|
||||
/// <returns></returns>
|
||||
public static bool AreSpecificKeysPressed(out Key[] pressedKey, params Key[] keys)
|
||||
{
|
||||
return AreSpecificKeysPressed(false, out pressedKey, keys);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if any of the specific keys are pressed and returns them.
|
||||
/// </summary>
|
||||
/// <param name="once">If true, it ignores keys that were down a state before.</param>
|
||||
/// <param name="pressedKeys"></param>
|
||||
/// <param name="keys"></param>
|
||||
/// <returns></returns>
|
||||
public static bool AreSpecificKeysPressed(bool once, out Key[] pressedKeys, params Key[] keys)
|
||||
{
|
||||
List<Key> pressedKey = new List<Key>();
|
||||
bool success = false;
|
||||
|
||||
foreach (Key key in keys)
|
||||
{
|
||||
if (IsDown(key, once))
|
||||
{
|
||||
pressedKey.Add(key);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
pressedKeys = pressedKey.ToArray();
|
||||
return success;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue