KeyboardKeyAssigner.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using OpenTK.Input;
  2. using System;
  3. using Key = Ryujinx.Configuration.Hid.Key;
  4. namespace Ryujinx.Ui.Input
  5. {
  6. class KeyboardKeyAssigner : ButtonAssigner
  7. {
  8. private int _index;
  9. private KeyboardState _keyboardState;
  10. public KeyboardKeyAssigner(int index)
  11. {
  12. _index = index;
  13. }
  14. public void Init() { }
  15. public void ReadInput()
  16. {
  17. _keyboardState = KeyboardController.GetKeyboardState(_index);
  18. }
  19. public bool HasAnyButtonPressed()
  20. {
  21. return _keyboardState.IsAnyKeyDown;
  22. }
  23. public bool ShouldCancel()
  24. {
  25. return Mouse.GetState().IsAnyButtonDown || Keyboard.GetState().IsKeyDown(OpenTK.Input.Key.Escape);
  26. }
  27. public string GetPressedButton()
  28. {
  29. string keyPressed = "";
  30. foreach (Key key in Enum.GetValues(typeof(Key)))
  31. {
  32. if (_keyboardState.IsKeyDown((OpenTK.Input.Key)key))
  33. {
  34. keyPressed = key.ToString();
  35. break;
  36. }
  37. }
  38. return !ShouldCancel() ? keyPressed : "";
  39. }
  40. }
  41. }