KeyboardKeyAssigner.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. namespace Ryujinx.Input.Assigner
  2. {
  3. /// <summary>
  4. /// <see cref="IButtonAssigner"/> implementation for <see cref="IKeyboard"/>.
  5. /// </summary>
  6. public class KeyboardKeyAssigner : IButtonAssigner
  7. {
  8. private IKeyboard _keyboard;
  9. private KeyboardStateSnapshot _keyboardState;
  10. public KeyboardKeyAssigner(IKeyboard keyboard)
  11. {
  12. _keyboard = keyboard;
  13. }
  14. public void Initialize() { }
  15. public void ReadInput()
  16. {
  17. _keyboardState = _keyboard.GetKeyboardStateSnapshot();
  18. }
  19. public bool HasAnyButtonPressed()
  20. {
  21. return GetPressedButton().Length != 0;
  22. }
  23. public bool ShouldCancel()
  24. {
  25. return _keyboardState.IsPressed(Key.Escape);
  26. }
  27. public string GetPressedButton()
  28. {
  29. string keyPressed = "";
  30. for (Key key = Key.Unknown; key < Key.Count; key++)
  31. {
  32. if (_keyboardState.IsPressed(key))
  33. {
  34. keyPressed = key.ToString();
  35. break;
  36. }
  37. }
  38. return !ShouldCancel() ? keyPressed : "";
  39. }
  40. }
  41. }