GTK3MappingHelper.cs 4.6 KB

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