IKeyboard.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Runtime.CompilerServices;
  2. namespace Ryujinx.Input
  3. {
  4. /// <summary>
  5. /// Represent an emulated keyboard.
  6. /// </summary>
  7. public interface IKeyboard : IGamepad
  8. {
  9. /// <summary>
  10. /// Check if a given key is pressed on the keyboard.
  11. /// </summary>
  12. /// <param name="key">The key</param>
  13. /// <returns>True if the given key is pressed on the keyboard</returns>
  14. bool IsPressed(Key key);
  15. /// <summary>
  16. /// Get a snaphost of the state of the keyboard.
  17. /// </summary>
  18. /// <returns>A snaphost of the state of the keyboard.</returns>
  19. KeyboardStateSnapshot GetKeyboardStateSnapshot();
  20. /// <summary>
  21. /// Get a snaphost of the state of a keyboard.
  22. /// </summary>
  23. /// <param name="keyboard">The keyboard to do a snapshot of</param>
  24. /// <returns>A snaphost of the state of the keyboard.</returns>
  25. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  26. static KeyboardStateSnapshot GetStateSnapshot(IKeyboard keyboard)
  27. {
  28. bool[] keysState = new bool[(int)Key.Count];
  29. for (Key key = 0; key < Key.Count; key++)
  30. {
  31. keysState[(int)key] = keyboard.IsPressed(key);
  32. }
  33. return new KeyboardStateSnapshot(keysState);
  34. }
  35. }
  36. }