JoyConKeyboard.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using OpenTK.Input;
  2. using Ryujinx.HLE.Input;
  3. namespace Ryujinx.UI.Input
  4. {
  5. public struct JoyConKeyboardLeft
  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 JoyConKeyboardRight
  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 JoyConKeyboard
  36. {
  37. public JoyConKeyboardLeft Left;
  38. public JoyConKeyboardRight Right;
  39. public JoyConKeyboard(
  40. JoyConKeyboardLeft Left,
  41. JoyConKeyboardRight Right)
  42. {
  43. this.Left = Left;
  44. this.Right = Right;
  45. }
  46. public HidControllerButtons GetButtons(KeyboardState Keyboard)
  47. {
  48. HidControllerButtons Buttons = 0;
  49. if (Keyboard[(Key)Left.StickButton]) Buttons |= HidControllerButtons.KEY_LSTICK;
  50. if (Keyboard[(Key)Left.DPadUp]) Buttons |= HidControllerButtons.KEY_DUP;
  51. if (Keyboard[(Key)Left.DPadDown]) Buttons |= HidControllerButtons.KEY_DDOWN;
  52. if (Keyboard[(Key)Left.DPadLeft]) Buttons |= HidControllerButtons.KEY_DLEFT;
  53. if (Keyboard[(Key)Left.DPadRight]) Buttons |= HidControllerButtons.KEY_DRIGHT;
  54. if (Keyboard[(Key)Left.ButtonMinus]) Buttons |= HidControllerButtons.KEY_MINUS;
  55. if (Keyboard[(Key)Left.ButtonL]) Buttons |= HidControllerButtons.KEY_L;
  56. if (Keyboard[(Key)Left.ButtonZL]) Buttons |= HidControllerButtons.KEY_ZL;
  57. if (Keyboard[(Key)Right.StickButton]) Buttons |= HidControllerButtons.KEY_RSTICK;
  58. if (Keyboard[(Key)Right.ButtonA]) Buttons |= HidControllerButtons.KEY_A;
  59. if (Keyboard[(Key)Right.ButtonB]) Buttons |= HidControllerButtons.KEY_B;
  60. if (Keyboard[(Key)Right.ButtonX]) Buttons |= HidControllerButtons.KEY_X;
  61. if (Keyboard[(Key)Right.ButtonY]) Buttons |= HidControllerButtons.KEY_Y;
  62. if (Keyboard[(Key)Right.ButtonPlus]) Buttons |= HidControllerButtons.KEY_PLUS;
  63. if (Keyboard[(Key)Right.ButtonR]) Buttons |= HidControllerButtons.KEY_R;
  64. if (Keyboard[(Key)Right.ButtonZR]) Buttons |= HidControllerButtons.KEY_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. }