NpadKeyboard.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using OpenTK.Input;
  2. using Ryujinx.HLE.Input;
  3. namespace Ryujinx.UI.Input
  4. {
  5. public struct NpadKeyboardLeft
  6. {
  7. public Key StickUp;
  8. public Key StickDown;
  9. public Key StickLeft;
  10. public Key StickRight;
  11. public Key StickButton;
  12. public Key DPadUp;
  13. public Key DPadDown;
  14. public Key DPadLeft;
  15. public Key DPadRight;
  16. public Key ButtonMinus;
  17. public Key ButtonL;
  18. public Key ButtonZl;
  19. }
  20. public struct NpadKeyboardRight
  21. {
  22. public Key StickUp;
  23. public Key StickDown;
  24. public Key StickLeft;
  25. public Key StickRight;
  26. public Key StickButton;
  27. public Key ButtonA;
  28. public Key ButtonB;
  29. public Key ButtonX;
  30. public Key ButtonY;
  31. public Key ButtonPlus;
  32. public Key ButtonR;
  33. public Key ButtonZr;
  34. }
  35. public struct KeyboardHotkeys
  36. {
  37. public Key ToggleVsync;
  38. }
  39. public class NpadKeyboard
  40. {
  41. /// <summary>
  42. /// Left JoyCon Keyboard Bindings
  43. /// </summary>
  44. public NpadKeyboardLeft LeftJoycon { get; private set; }
  45. /// <summary>
  46. /// Right JoyCon Keyboard Bindings
  47. /// </summary>
  48. public NpadKeyboardRight RightJoycon { get; private set; }
  49. /// <summary>
  50. /// Hotkey Keyboard Bindings
  51. /// </summary>
  52. public KeyboardHotkeys Hotkeys { get; private set; }
  53. public HidControllerButtons GetButtons(KeyboardState keyboard)
  54. {
  55. HidControllerButtons buttons = 0;
  56. if (keyboard[(Key)LeftJoycon.StickButton]) buttons |= HidControllerButtons.StickLeft;
  57. if (keyboard[(Key)LeftJoycon.DPadUp]) buttons |= HidControllerButtons.DpadUp;
  58. if (keyboard[(Key)LeftJoycon.DPadDown]) buttons |= HidControllerButtons.DpadDown;
  59. if (keyboard[(Key)LeftJoycon.DPadLeft]) buttons |= HidControllerButtons.DpadLeft;
  60. if (keyboard[(Key)LeftJoycon.DPadRight]) buttons |= HidControllerButtons.DPadRight;
  61. if (keyboard[(Key)LeftJoycon.ButtonMinus]) buttons |= HidControllerButtons.Minus;
  62. if (keyboard[(Key)LeftJoycon.ButtonL]) buttons |= HidControllerButtons.L;
  63. if (keyboard[(Key)LeftJoycon.ButtonZl]) buttons |= HidControllerButtons.Zl;
  64. if (keyboard[(Key)RightJoycon.StickButton]) buttons |= HidControllerButtons.StickRight;
  65. if (keyboard[(Key)RightJoycon.ButtonA]) buttons |= HidControllerButtons.A;
  66. if (keyboard[(Key)RightJoycon.ButtonB]) buttons |= HidControllerButtons.B;
  67. if (keyboard[(Key)RightJoycon.ButtonX]) buttons |= HidControllerButtons.X;
  68. if (keyboard[(Key)RightJoycon.ButtonY]) buttons |= HidControllerButtons.Y;
  69. if (keyboard[(Key)RightJoycon.ButtonPlus]) buttons |= HidControllerButtons.Plus;
  70. if (keyboard[(Key)RightJoycon.ButtonR]) buttons |= HidControllerButtons.R;
  71. if (keyboard[(Key)RightJoycon.ButtonZr]) buttons |= HidControllerButtons.Zr;
  72. return buttons;
  73. }
  74. public (short, short) GetLeftStick(KeyboardState keyboard)
  75. {
  76. short dx = 0;
  77. short dy = 0;
  78. if (keyboard[(Key)LeftJoycon.StickUp]) dy = short.MaxValue;
  79. if (keyboard[(Key)LeftJoycon.StickDown]) dy = -short.MaxValue;
  80. if (keyboard[(Key)LeftJoycon.StickLeft]) dx = -short.MaxValue;
  81. if (keyboard[(Key)LeftJoycon.StickRight]) dx = short.MaxValue;
  82. return (dx, dy);
  83. }
  84. public (short, short) GetRightStick(KeyboardState keyboard)
  85. {
  86. short dx = 0;
  87. short dy = 0;
  88. if (keyboard[(Key)RightJoycon.StickUp]) dy = short.MaxValue;
  89. if (keyboard[(Key)RightJoycon.StickDown]) dy = -short.MaxValue;
  90. if (keyboard[(Key)RightJoycon.StickLeft]) dx = -short.MaxValue;
  91. if (keyboard[(Key)RightJoycon.StickRight]) dx = short.MaxValue;
  92. return (dx, dy);
  93. }
  94. public HidHotkeyButtons GetHotkeyButtons(KeyboardState keyboard)
  95. {
  96. HidHotkeyButtons buttons = 0;
  97. if (keyboard[(Key)Hotkeys.ToggleVsync]) buttons |= HidHotkeyButtons.ToggleVSync;
  98. return buttons;
  99. }
  100. }
  101. }