NpadKeyboard.cs 3.6 KB

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