NpadKeyboard.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 class NpadKeyboard
  36. {
  37. /// <summary>
  38. /// Left JoyCon Keyboard Bindings
  39. /// </summary>
  40. public NpadKeyboardLeft LeftJoycon { get; private set; }
  41. /// <summary>
  42. /// Right JoyCon Keyboard Bindings
  43. /// </summary>
  44. public NpadKeyboardRight RightJoycon { get; private set; }
  45. public HidControllerButtons GetButtons(KeyboardState keyboard)
  46. {
  47. HidControllerButtons buttons = 0;
  48. if (keyboard[(Key)LeftJoycon.StickButton]) buttons |= HidControllerButtons.StickLeft;
  49. if (keyboard[(Key)LeftJoycon.DPadUp]) buttons |= HidControllerButtons.DpadUp;
  50. if (keyboard[(Key)LeftJoycon.DPadDown]) buttons |= HidControllerButtons.DpadDown;
  51. if (keyboard[(Key)LeftJoycon.DPadLeft]) buttons |= HidControllerButtons.DpadLeft;
  52. if (keyboard[(Key)LeftJoycon.DPadRight]) buttons |= HidControllerButtons.DPadRight;
  53. if (keyboard[(Key)LeftJoycon.ButtonMinus]) buttons |= HidControllerButtons.Minus;
  54. if (keyboard[(Key)LeftJoycon.ButtonL]) buttons |= HidControllerButtons.L;
  55. if (keyboard[(Key)LeftJoycon.ButtonZl]) buttons |= HidControllerButtons.Zl;
  56. if (keyboard[(Key)RightJoycon.StickButton]) buttons |= HidControllerButtons.StickRight;
  57. if (keyboard[(Key)RightJoycon.ButtonA]) buttons |= HidControllerButtons.A;
  58. if (keyboard[(Key)RightJoycon.ButtonB]) buttons |= HidControllerButtons.B;
  59. if (keyboard[(Key)RightJoycon.ButtonX]) buttons |= HidControllerButtons.X;
  60. if (keyboard[(Key)RightJoycon.ButtonY]) buttons |= HidControllerButtons.Y;
  61. if (keyboard[(Key)RightJoycon.ButtonPlus]) buttons |= HidControllerButtons.Plus;
  62. if (keyboard[(Key)RightJoycon.ButtonR]) buttons |= HidControllerButtons.R;
  63. if (keyboard[(Key)RightJoycon.ButtonZr]) buttons |= HidControllerButtons.Zr;
  64. return buttons;
  65. }
  66. public (short, short) GetLeftStick(KeyboardState keyboard)
  67. {
  68. short dx = 0;
  69. short dy = 0;
  70. if (keyboard[(Key)LeftJoycon.StickUp]) dy = short.MaxValue;
  71. if (keyboard[(Key)LeftJoycon.StickDown]) dy = -short.MaxValue;
  72. if (keyboard[(Key)LeftJoycon.StickLeft]) dx = -short.MaxValue;
  73. if (keyboard[(Key)LeftJoycon.StickRight]) dx = short.MaxValue;
  74. return (dx, dy);
  75. }
  76. public (short, short) GetRightStick(KeyboardState keyboard)
  77. {
  78. short dx = 0;
  79. short dy = 0;
  80. if (keyboard[(Key)RightJoycon.StickUp]) dy = short.MaxValue;
  81. if (keyboard[(Key)RightJoycon.StickDown]) dy = -short.MaxValue;
  82. if (keyboard[(Key)RightJoycon.StickLeft]) dx = -short.MaxValue;
  83. if (keyboard[(Key)RightJoycon.StickRight]) dx = short.MaxValue;
  84. return (dx, dy);
  85. }
  86. }
  87. }