GTK3MappingHelper.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.CompilerServices;
  5. using GtkKey = Gdk.Key;
  6. namespace Ryujinx.Input.GTK3
  7. {
  8. public static class GTK3MappingHelper
  9. {
  10. private static readonly GtkKey[] _keyMapping = new GtkKey[(int)Key.Count]
  11. {
  12. // NOTE: invalid
  13. GtkKey.blank,
  14. GtkKey.Shift_L,
  15. GtkKey.Shift_R,
  16. GtkKey.Control_L,
  17. GtkKey.Control_R,
  18. GtkKey.Alt_L,
  19. GtkKey.Alt_R,
  20. GtkKey.Super_L,
  21. GtkKey.Super_R,
  22. GtkKey.Menu,
  23. GtkKey.F1,
  24. GtkKey.F2,
  25. GtkKey.F3,
  26. GtkKey.F4,
  27. GtkKey.F5,
  28. GtkKey.F6,
  29. GtkKey.F7,
  30. GtkKey.F8,
  31. GtkKey.F9,
  32. GtkKey.F10,
  33. GtkKey.F11,
  34. GtkKey.F12,
  35. GtkKey.F13,
  36. GtkKey.F14,
  37. GtkKey.F15,
  38. GtkKey.F16,
  39. GtkKey.F17,
  40. GtkKey.F18,
  41. GtkKey.F19,
  42. GtkKey.F20,
  43. GtkKey.F21,
  44. GtkKey.F22,
  45. GtkKey.F23,
  46. GtkKey.F24,
  47. GtkKey.F25,
  48. GtkKey.F26,
  49. GtkKey.F27,
  50. GtkKey.F28,
  51. GtkKey.F29,
  52. GtkKey.F30,
  53. GtkKey.F31,
  54. GtkKey.F32,
  55. GtkKey.F33,
  56. GtkKey.F34,
  57. GtkKey.F35,
  58. GtkKey.Up,
  59. GtkKey.Down,
  60. GtkKey.Left,
  61. GtkKey.Right,
  62. GtkKey.Return,
  63. GtkKey.Escape,
  64. GtkKey.space,
  65. GtkKey.Tab,
  66. GtkKey.BackSpace,
  67. GtkKey.Insert,
  68. GtkKey.Delete,
  69. GtkKey.Page_Up,
  70. GtkKey.Page_Down,
  71. GtkKey.Home,
  72. GtkKey.End,
  73. GtkKey.Caps_Lock,
  74. GtkKey.Scroll_Lock,
  75. GtkKey.Print,
  76. GtkKey.Pause,
  77. GtkKey.Num_Lock,
  78. GtkKey.Clear,
  79. GtkKey.KP_0,
  80. GtkKey.KP_1,
  81. GtkKey.KP_2,
  82. GtkKey.KP_3,
  83. GtkKey.KP_4,
  84. GtkKey.KP_5,
  85. GtkKey.KP_6,
  86. GtkKey.KP_7,
  87. GtkKey.KP_8,
  88. GtkKey.KP_9,
  89. GtkKey.KP_Divide,
  90. GtkKey.KP_Multiply,
  91. GtkKey.KP_Subtract,
  92. GtkKey.KP_Add,
  93. GtkKey.KP_Decimal,
  94. GtkKey.KP_Enter,
  95. GtkKey.a,
  96. GtkKey.b,
  97. GtkKey.c,
  98. GtkKey.d,
  99. GtkKey.e,
  100. GtkKey.f,
  101. GtkKey.g,
  102. GtkKey.h,
  103. GtkKey.i,
  104. GtkKey.j,
  105. GtkKey.k,
  106. GtkKey.l,
  107. GtkKey.m,
  108. GtkKey.n,
  109. GtkKey.o,
  110. GtkKey.p,
  111. GtkKey.q,
  112. GtkKey.r,
  113. GtkKey.s,
  114. GtkKey.t,
  115. GtkKey.u,
  116. GtkKey.v,
  117. GtkKey.w,
  118. GtkKey.x,
  119. GtkKey.y,
  120. GtkKey.z,
  121. GtkKey.Key_0,
  122. GtkKey.Key_1,
  123. GtkKey.Key_2,
  124. GtkKey.Key_3,
  125. GtkKey.Key_4,
  126. GtkKey.Key_5,
  127. GtkKey.Key_6,
  128. GtkKey.Key_7,
  129. GtkKey.Key_8,
  130. GtkKey.Key_9,
  131. GtkKey.grave,
  132. GtkKey.grave,
  133. GtkKey.minus,
  134. GtkKey.plus,
  135. GtkKey.bracketleft,
  136. GtkKey.bracketright,
  137. GtkKey.semicolon,
  138. GtkKey.quoteright,
  139. GtkKey.comma,
  140. GtkKey.period,
  141. GtkKey.slash,
  142. GtkKey.backslash,
  143. // NOTE: invalid
  144. GtkKey.blank,
  145. };
  146. private static readonly Dictionary<GtkKey, Key> _gtkKeyMapping;
  147. static GTK3MappingHelper()
  148. {
  149. var inputKeys = Enum.GetValues<Key>().SkipLast(1);
  150. // GtkKey is not contiguous and quite large, so use a dictionary instead of an array.
  151. _gtkKeyMapping = new Dictionary<GtkKey, Key>();
  152. foreach (var key in inputKeys)
  153. {
  154. var index = ToGtkKey(key);
  155. _gtkKeyMapping[index] = key;
  156. }
  157. }
  158. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  159. public static GtkKey ToGtkKey(Key key)
  160. {
  161. return _keyMapping[(int)key];
  162. }
  163. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  164. public static Key ToInputKey(GtkKey key)
  165. {
  166. return _gtkKeyMapping.GetValueOrDefault(key, Key.Unknown);
  167. }
  168. }
  169. }