KeyboardState.Extensions.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using Microsoft.Xna.Framework.Input;
  3. namespace MonoGame.Extended.Input
  4. {
  5. public static class KeyboardStateExtensions
  6. {
  7. #if FNA
  8. // MomoGame compatibility layer
  9. /// <summary>
  10. /// Fills an array of values holding keys that are currently being pressed.
  11. /// Note: This extension method is not allocation free when targeting FNA.
  12. /// </summary>
  13. /// <param name="keys">The keys array to fill.
  14. internal static void GetPressedKeys(this KeyboardState value, Keys[] keys)
  15. {
  16. Keys[] pressedKeys = value.GetPressedKeys();
  17. Array.Copy(pressedKeys, keys, pressedKeys.Length);
  18. }
  19. /// <summary>
  20. /// Returns the number of pressed keys in this KeyboardState.
  21. /// </summary>
  22. /// Note: This extension method is not allocation free when targeting FNA.
  23. /// <returns>An integer representing the number of keys currently pressed in this KeyboardState.</returns>
  24. internal static int GetPressedKeyCount(this KeyboardState value)
  25. {
  26. Keys[] pressedKeys = value.GetPressedKeys();
  27. return pressedKeys.Length;
  28. }
  29. #endif
  30. }
  31. }