Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using UnityEngine.InputSystem.Controls;
  4. using UnityEngine.InputSystem.LowLevel;
  5. using UnityEngine.InputSystem.Utilities;
  6. using Unity.Collections.LowLevel.Unsafe;
  7. using UnityEngine.InputSystem.Layouts;
  8. ////FIXME: display names for keys should be localized key names, not just printable characters (e.g. "Space" should be called "Leertaste")
  9. ////TODO: usages on modifiers so they can be identified regardless of platform conventions
  10. namespace UnityEngine.InputSystem.LowLevel
  11. {
  12. /// <summary>
  13. /// Default state layout for keyboards.
  14. /// </summary>
  15. /// <remarks>
  16. /// Can be used to update the state of <see cref="Keyboard"/> devices.
  17. ///
  18. /// <example>
  19. /// <code>
  20. /// // Send input event with A key pressed on keyboard.
  21. /// InputSystem.QueueStateEvent(Keyboard.current,
  22. /// new KeyboardState(Key.A));
  23. /// </code>
  24. /// </example>
  25. /// </remarks>
  26. /// <seealso cref="Keyboard"/>
  27. // NOTE: This layout has to match the KeyboardInputState layout used in native!
  28. [StructLayout(LayoutKind.Sequential)]
  29. public unsafe struct KeyboardState : IInputStateTypeInfo
  30. {
  31. /// <summary>
  32. /// Memory format tag for KeybboardState.
  33. /// </summary>
  34. /// <value>Returns "KEYS".</value>
  35. /// <seealso cref="InputStateBlock.format"/>
  36. public static FourCC Format => new FourCC('K', 'E', 'Y', 'S');
  37. private const int kSizeInBits = Keyboard.KeyCount;
  38. internal const int kSizeInBytes = (kSizeInBits + 7) / 8;
  39. [InputControl(name = "anyKey", displayName = "Any Key", layout = "AnyKey", sizeInBits = kSizeInBits - 1, synthetic = true)] // Exclude IMESelected.
  40. [InputControl(name = "escape", displayName = "Escape", layout = "Key", usages = new[] {"Back", "Cancel"}, bit = (int)Key.Escape)]
  41. [InputControl(name = "space", displayName = "Space", layout = "Key", bit = (int)Key.Space)]
  42. [InputControl(name = "enter", displayName = "Enter", layout = "Key", usage = "Submit", bit = (int)Key.Enter)]
  43. [InputControl(name = "tab", displayName = "Tab", layout = "Key", bit = (int)Key.Tab)]
  44. [InputControl(name = "backquote", displayName = "`", layout = "Key", bit = (int)Key.Backquote)]
  45. [InputControl(name = "quote", displayName = "'", layout = "Key", bit = (int)Key.Quote)]
  46. [InputControl(name = "semicolon", displayName = ";", layout = "Key", bit = (int)Key.Semicolon)]
  47. [InputControl(name = "comma", displayName = ",", layout = "Key", bit = (int)Key.Comma)]
  48. [InputControl(name = "period", displayName = ".", layout = "Key", bit = (int)Key.Period)]
  49. [InputControl(name = "slash", displayName = "/", layout = "Key", bit = (int)Key.Slash)]
  50. [InputControl(name = "backslash", displayName = "\\", layout = "Key", bit = (int)Key.Backslash)]
  51. [InputControl(name = "leftBracket", displayName = "[", layout = "Key", bit = (int)Key.LeftBracket)]
  52. [InputControl(name = "rightBracket", displayName = "]", layout = "Key", bit = (int)Key.RightBracket)]
  53. [InputControl(name = "minus", displayName = "-", layout = "Key", bit = (int)Key.Minus)]
  54. [InputControl(name = "equals", displayName = "=", layout = "Key", bit = (int)Key.Equals)]
  55. [InputControl(name = "upArrow", displayName = "Up Arrow", layout = "Key", bit = (int)Key.UpArrow)]
  56. [InputControl(name = "downArrow", displayName = "Down Arrow", layout = "Key", bit = (int)Key.DownArrow)]
  57. [InputControl(name = "leftArrow", displayName = "Left Arrow", layout = "Key", bit = (int)Key.LeftArrow)]
  58. [InputControl(name = "rightArrow", displayName = "Right Arrow", layout = "Key", bit = (int)Key.RightArrow)]
  59. [InputControl(name = "a", displayName = "A", layout = "Key", bit = (int)Key.A)]
  60. [InputControl(name = "b", displayName = "B", layout = "Key", bit = (int)Key.B)]
  61. [InputControl(name = "c", displayName = "C", layout = "Key", bit = (int)Key.C)]
  62. [InputControl(name = "d", displayName = "D", layout = "Key", bit = (int)Key.D)]
  63. [InputControl(name = "e", displayName = "E", layout = "Key", bit = (int)Key.E)]
  64. [InputControl(name = "f", displayName = "F", layout = "Key", bit = (int)Key.F)]
  65. [InputControl(name = "g", displayName = "G", layout = "Key", bit = (int)Key.G)]
  66. [InputControl(name = "h", displayName = "H", layout = "Key", bit = (int)Key.H)]
  67. [InputControl(name = "i", displayName = "I", layout = "Key", bit = (int)Key.I)]
  68. [InputControl(name = "j", displayName = "J", layout = "Key", bit = (int)Key.J)]
  69. [InputControl(name = "k", displayName = "K", layout = "Key", bit = (int)Key.K)]
  70. [InputControl(name = "l", displayName = "L", layout = "Key", bit = (int)Key.L)]
  71. [InputControl(name = "m", displayName = "M", layout = "Key", bit = (int)Key.M)]
  72. [InputControl(name = "n", displayName = "N", layout = "Key", bit = (int)Key.N)]
  73. [InputControl(name = "o", displayName = "O", layout = "Key", bit = (int)Key.O)]
  74. [InputControl(name = "p", displayName = "P", layout = "Key", bit = (int)Key.P)]
  75. [InputControl(name = "q", displayName = "Q", layout = "Key", bit = (int)Key.Q)]
  76. [InputControl(name = "r", displayName = "R", layout = "Key", bit = (int)Key.R)]
  77. [InputControl(name = "s", displayName = "S", layout = "Key", bit = (int)Key.S)]
  78. [InputControl(name = "t", displayName = "T", layout = "Key", bit = (int)Key.T)]
  79. [InputControl(name = "u", displayName = "U", layout = "Key", bit = (int)Key.U)]
  80. [InputControl(name = "v", displayName = "V", layout = "Key", bit = (int)Key.V)]
  81. [InputControl(name = "w", displayName = "W", layout = "Key", bit = (int)Key.W)]
  82. [InputControl(name = "x", displayName = "X", layout = "Key", bit = (int)Key.X)]
  83. [InputControl(name = "y", displayName = "Y", layout = "Key", bit = (int)Key.Y)]
  84. [InputControl(name = "z", displayName = "Z", layout = "Key", bit = (int)Key.Z)]
  85. [InputControl(name = "1", displayName = "1", layout = "Key", bit = (int)Key.Digit1)]
  86. [InputControl(name = "2", displayName = "2", layout = "Key", bit = (int)Key.Digit2)]
  87. [InputControl(name = "3", displayName = "3", layout = "Key", bit = (int)Key.Digit3)]
  88. [InputControl(name = "4", displayName = "4", layout = "Key", bit = (int)Key.Digit4)]
  89. [InputControl(name = "5", displayName = "5", layout = "Key", bit = (int)Key.Digit5)]
  90. [InputControl(name = "6", displayName = "6", layout = "Key", bit = (int)Key.Digit6)]
  91. [InputControl(name = "7", displayName = "7", layout = "Key", bit = (int)Key.Digit7)]
  92. [InputControl(name = "8", displayName = "8", layout = "Key", bit = (int)Key.Digit8)]
  93. [InputControl(name = "9", displayName = "9", layout = "Key", bit = (int)Key.Digit9)]
  94. [InputControl(name = "0", displayName = "0", layout = "Key", bit = (int)Key.Digit0)]
  95. [InputControl(name = "leftShift", displayName = "Left Shift", layout = "Key", usage = "Modifier", bit = (int)Key.LeftShift)]
  96. [InputControl(name = "rightShift", displayName = "Right Shift", layout = "Key", usage = "Modifier", bit = (int)Key.RightShift)]
  97. [InputControl(name = "shift", displayName = "Shift", layout = "DiscreteButton", usage = "Modifier", bit = (int)Key.LeftShift, sizeInBits = 2, synthetic = true, parameters = "minValue=1,maxValue=3,writeMode=1")]
  98. [InputControl(name = "leftAlt", displayName = "Left Alt", layout = "Key", usage = "Modifier", bit = (int)Key.LeftAlt)]
  99. [InputControl(name = "rightAlt", displayName = "Right Alt", layout = "Key", usage = "Modifier", bit = (int)Key.RightAlt, alias = "AltGr")]
  100. [InputControl(name = "alt", displayName = "Alt", layout = "DiscreteButton", usage = "Modifier", bit = (int)Key.LeftAlt, sizeInBits = 2, synthetic = true, parameters = "minValue=1,maxValue=3,writeMode=1")]
  101. [InputControl(name = "leftCtrl", displayName = "Left Control", layout = "Key", usage = "Modifier", bit = (int)Key.LeftCtrl)]
  102. [InputControl(name = "rightCtrl", displayName = "Right Control", layout = "Key", usage = "Modifier", bit = (int)Key.RightCtrl)]
  103. [InputControl(name = "ctrl", displayName = "Control", layout = "DiscreteButton", usage = "Modifier", bit = (int)Key.LeftCtrl, sizeInBits = 2, synthetic = true, parameters = "minValue=1,maxValue=3,writeMode=1")]
  104. [InputControl(name = "leftMeta", displayName = "Left System", layout = "Key", usage = "Modifier", bit = (int)Key.LeftMeta, aliases = new[] { "LeftWindows", "LeftApple", "LeftCommand" })]
  105. [InputControl(name = "rightMeta", displayName = "Right System", layout = "Key", usage = "Modifier", bit = (int)Key.RightMeta, aliases = new[] { "RightWindows", "RightApple", "RightCommand" })]
  106. [InputControl(name = "contextMenu", displayName = "Context Menu", layout = "Key", usage = "Modifier", bit = (int)Key.ContextMenu)]
  107. [InputControl(name = "backspace", displayName = "Backspace", layout = "Key", bit = (int)Key.Backspace)]
  108. [InputControl(name = "pageDown", displayName = "Page Down", layout = "Key", bit = (int)Key.PageDown)]
  109. [InputControl(name = "pageUp", displayName = "Page Up", layout = "Key", bit = (int)Key.PageUp)]
  110. [InputControl(name = "home", displayName = "Home", layout = "Key", bit = (int)Key.Home)]
  111. [InputControl(name = "end", displayName = "End", layout = "Key", bit = (int)Key.End)]
  112. [InputControl(name = "insert", displayName = "Insert", layout = "Key", bit = (int)Key.Insert)]
  113. [InputControl(name = "delete", displayName = "Delete", layout = "Key", bit = (int)Key.Delete)]
  114. [InputControl(name = "capsLock", displayName = "Caps Lock", layout = "Key", bit = (int)Key.CapsLock)]
  115. [InputControl(name = "numLock", displayName = "Num Lock", layout = "Key", bit = (int)Key.NumLock)]
  116. [InputControl(name = "printScreen", displayName = "Print Screen", layout = "Key", bit = (int)Key.PrintScreen)]
  117. [InputControl(name = "scrollLock", displayName = "Scroll Lock", layout = "Key", bit = (int)Key.ScrollLock)]
  118. [InputControl(name = "pause", displayName = "Pause/Break", layout = "Key", bit = (int)Key.Pause)]
  119. [InputControl(name = "numpadEnter", displayName = "Numpad Enter", layout = "Key", bit = (int)Key.NumpadEnter)]
  120. [InputControl(name = "numpadDivide", displayName = "Numpad /", layout = "Key", bit = (int)Key.NumpadDivide)]
  121. [InputControl(name = "numpadMultiply", displayName = "Numpad *", layout = "Key", bit = (int)Key.NumpadMultiply)]
  122. [InputControl(name = "numpadPlus", displayName = "Numpad +", layout = "Key", bit = (int)Key.NumpadPlus)]
  123. [InputControl(name = "numpadMinus", displayName = "Numpad -", layout = "Key", bit = (int)Key.NumpadMinus)]
  124. [InputControl(name = "numpadPeriod", displayName = "Numpad .", layout = "Key", bit = (int)Key.NumpadPeriod)]
  125. [InputControl(name = "numpadEquals", displayName = "Numpad =", layout = "Key", bit = (int)Key.NumpadEquals)]
  126. [InputControl(name = "numpad1", displayName = "Numpad 1", layout = "Key", bit = (int)Key.Numpad1)]
  127. [InputControl(name = "numpad2", displayName = "Numpad 2", layout = "Key", bit = (int)Key.Numpad2)]
  128. [InputControl(name = "numpad3", displayName = "Numpad 3", layout = "Key", bit = (int)Key.Numpad3)]
  129. [InputControl(name = "numpad4", displayName = "Numpad 4", layout = "Key", bit = (int)Key.Numpad4)]
  130. [InputControl(name = "numpad5", displayName = "Numpad 5", layout = "Key", bit = (int)Key.Numpad5)]
  131. [InputControl(name = "numpad6", displayName = "Numpad 6", layout = "Key", bit = (int)Key.Numpad6)]
  132. [InputControl(name = "numpad7", displayName = "Numpad 7", layout = "Key", bit = (int)Key.Numpad7)]
  133. [InputControl(name = "numpad8", displayName = "Numpad 8", layout = "Key", bit = (int)Key.Numpad8)]
  134. [InputControl(name = "numpad9", displayName = "Numpad 9", layout = "Key", bit = (int)Key.Numpad9)]
  135. [InputControl(name = "numpad0", displayName = "Numpad 0", layout = "Key", bit = (int)Key.Numpad0)]
  136. [InputControl(name = "f1", displayName = "F1", layout = "Key", bit = (int)Key.F1)]
  137. [InputControl(name = "f2", displayName = "F2", layout = "Key", bit = (int)Key.F2)]
  138. [InputControl(name = "f3", displayName = "F3", layout = "Key", bit = (int)Key.F3)]
  139. [InputControl(name = "f4", displayName = "F4", layout = "Key", bit = (int)Key.F4)]
  140. [InputControl(name = "f5", displayName = "F5", layout = "Key", bit = (int)Key.F5)]
  141. [InputControl(name = "f6", displayName = "F6", layout = "Key", bit = (int)Key.F6)]
  142. [InputControl(name = "f7", displayName = "F7", layout = "Key", bit = (int)Key.F7)]
  143. [InputControl(name = "f8", displayName = "F8", layout = "Key", bit = (int)Key.F8)]
  144. [InputControl(name = "f9", displayName = "F9", layout = "Key", bit = (int)Key.F9)]
  145. [InputControl(name = "f10", displayName = "F10", layout = "Key", bit = (int)Key.F10)]
  146. [InputControl(name = "f11", displayName = "F11", layout = "Key", bit = (int)Key.F11)]
  147. [InputControl(name = "f12", displayName = "F12", layout = "Key", bit = (int)Key.F12)]
  148. [InputControl(name = "OEM1", layout = "Key", bit = (int)Key.OEM1)]
  149. [InputControl(name = "OEM2", layout = "Key", bit = (int)Key.OEM2)]
  150. [InputControl(name = "OEM3", layout = "Key", bit = (int)Key.OEM3)]
  151. [InputControl(name = "OEM4", layout = "Key", bit = (int)Key.OEM4)]
  152. [InputControl(name = "OEM5", layout = "Key", bit = (int)Key.OEM5)]
  153. [InputControl(name = "IMESelected", layout = "Button", bit = (int)Key.IMESelected, synthetic = true)]
  154. public fixed byte keys[kSizeInBytes];
  155. public KeyboardState(params Key[] pressedKeys)
  156. {
  157. if (pressedKeys == null)
  158. throw new ArgumentNullException(nameof(pressedKeys));
  159. fixed(byte* keysPtr = keys)
  160. {
  161. UnsafeUtility.MemClear(keysPtr, kSizeInBytes);
  162. for (var i = 0; i < pressedKeys.Length; ++i)
  163. MemoryHelpers.WriteSingleBit(keysPtr, (uint)pressedKeys[i], true);
  164. }
  165. }
  166. public void Set(Key key, bool state)
  167. {
  168. fixed(byte* keysPtr = keys)
  169. MemoryHelpers.WriteSingleBit(keysPtr, (uint)key, state);
  170. }
  171. public void Press(Key key)
  172. {
  173. Set(key, true);
  174. }
  175. public void Release(Key key)
  176. {
  177. Set(key, false);
  178. }
  179. public FourCC format => Format;
  180. }
  181. }
  182. namespace UnityEngine.InputSystem
  183. {
  184. /// <summary>
  185. /// Enumeration of key codes.
  186. /// </summary>
  187. /// <remarks>
  188. /// Named according to the US keyboard layout which is used as a reference layout.
  189. ///
  190. /// Note:
  191. /// Unity input system key codes and input manager key codes are designed with game controls in mind.
  192. ///
  193. /// This means the way they are assigned is intended to preserve the location of keys on keyboards,
  194. /// so that pressing a key in the same location on different keyboards should result in the same action
  195. /// regardless of what is printed on a key or what current system language is set.
  196. ///
  197. /// This means, for example, that <see cref="A"/> is always the key to the right of <see cref="CapsLock"/>,
  198. /// regardless of which key (if any) produces the "a" character on the current keyboard layout.
  199. ///
  200. /// Unity relies on physical hardware in the keyboards to report same USB HID "usage" for the keys in
  201. /// the same location.This puts a practical limit on what can be achieved, because different keyboards
  202. /// might report different data, and this is outside of Unity's control.
  203. ///
  204. /// For this reason, you should not use key codes to read text input.
  205. /// Instead, you should use the <see cref="Keyboard.onTextInput"/> callback.
  206. /// The `onTextInput` callback provides you with the actual text characters which correspond
  207. /// to the symbols printed on a keyboard, based on the end user's current system language layout.
  208. ///
  209. /// To find the text character (if any) generated by a key according to the currently active keyboard
  210. /// layout, use the <see cref="InputControl.displayName"/> property of <see cref="KeyControl"/>.
  211. ///
  212. /// <example>
  213. /// <code>
  214. /// // Look up key by key code.
  215. /// var aKey = Keyboard.current[Key.A];
  216. ///
  217. /// // Find out which text is produced by the key.
  218. /// Debug.Log($"The '{aKey.keyCode}' key produces '{aKey.displayName}' as text input");
  219. /// </code>
  220. /// </example>
  221. /// </remarks>
  222. // NOTE: Has to match up with 'KeyboardInputState::KeyCode' in native.
  223. // NOTE: In the keyboard code, we depend on the order of the keys in the various keyboard blocks.
  224. public enum Key
  225. {
  226. /// <summary>
  227. /// Invalid key. Does not represent a key on the keyboard and is only used to have a
  228. /// default for the Key enumeration not represent any specific key.
  229. /// </summary>
  230. None,
  231. // ---- Printable keys ----
  232. /// <summary>
  233. /// The <see cref="Keyboard.spaceKey"/>.
  234. /// </summary>
  235. Space,
  236. /// <summary>
  237. /// The <see cref="Keyboard.enterKey"/>.
  238. /// </summary>
  239. Enter,
  240. /// <summary>
  241. /// The <see cref="Keyboard.tabKey"/>.
  242. /// </summary>
  243. Tab,
  244. /// <summary>
  245. /// The <see cref="Keyboard.backquoteKey"/>.
  246. /// </summary>
  247. Backquote,
  248. /// <summary>
  249. /// The <see cref="Keyboard.quoteKey"/>.
  250. /// </summary>
  251. Quote,
  252. /// <summary>
  253. /// The <see cref="Keyboard.semicolonKey"/>.
  254. /// </summary>
  255. Semicolon,
  256. /// <summary>
  257. /// The <see cref="Keyboard.commaKey"/>.
  258. /// </summary>
  259. Comma,
  260. /// <summary>
  261. /// The <see cref="Keyboard.periodKey"/>.
  262. /// </summary>
  263. Period,
  264. /// <summary>
  265. /// The <see cref="Keyboard.slashKey"/>.
  266. /// </summary>
  267. Slash,
  268. /// <summary>
  269. /// The <see cref="Keyboard.backslashKey"/>.
  270. /// </summary>
  271. Backslash,
  272. /// <summary>
  273. /// The <see cref="Keyboard.leftBracketKey"/>.
  274. /// </summary>
  275. LeftBracket,
  276. /// <summary>
  277. /// The <see cref="Keyboard.rightBracketKey"/>.
  278. /// </summary>
  279. RightBracket,
  280. /// <summary>
  281. /// The <see cref="Keyboard.minusKey"/>.
  282. /// </summary>
  283. Minus,
  284. /// <summary>
  285. /// The <see cref="Keyboard.equalsKey"/>.
  286. /// </summary>
  287. Equals,
  288. /// <summary>
  289. /// The <see cref="Keyboard.aKey"/>.
  290. /// </summary>
  291. A,
  292. /// <summary>
  293. /// The <see cref="Keyboard.bKey"/>.
  294. /// </summary>
  295. B,
  296. /// <summary>
  297. /// The <see cref="Keyboard.cKey"/>.
  298. /// </summary>
  299. C,
  300. /// <summary>
  301. /// The <see cref="Keyboard.dKey"/>.
  302. /// </summary>
  303. D,
  304. /// <summary>
  305. /// The <see cref="Keyboard.eKey"/>.
  306. /// </summary>
  307. E,
  308. /// <summary>
  309. /// The <see cref="Keyboard.fKey"/>.
  310. /// </summary>
  311. F,
  312. /// <summary>
  313. /// The <see cref="Keyboard.gKey"/>.
  314. /// </summary>
  315. G,
  316. /// <summary>
  317. /// The <see cref="Keyboard.hKey"/>.
  318. /// </summary>
  319. H,
  320. /// <summary>
  321. /// The <see cref="Keyboard.iKey"/>.
  322. /// </summary>
  323. I,
  324. /// <summary>
  325. /// The <see cref="Keyboard.jKey"/>.
  326. /// </summary>
  327. J,
  328. /// <summary>
  329. /// The <see cref="Keyboard.kKey"/>.
  330. /// </summary>
  331. K,
  332. /// <summary>
  333. /// The <see cref="Keyboard.lKey"/>.
  334. /// </summary>
  335. L,
  336. /// <summary>
  337. /// The <see cref="Keyboard.mKey"/>.
  338. /// </summary>
  339. M,
  340. /// <summary>
  341. /// The <see cref="Keyboard.nKey"/>.
  342. /// </summary>
  343. N,
  344. /// <summary>
  345. /// The <see cref="Keyboard.oKey"/>.
  346. /// </summary>
  347. O,
  348. /// <summary>
  349. /// The <see cref="Keyboard.pKey"/>.
  350. /// </summary>
  351. P,
  352. /// <summary>
  353. /// The <see cref="Keyboard.qKey"/>.
  354. /// </summary>
  355. Q,
  356. /// <summary>
  357. /// The <see cref="Keyboard.rKey"/>.
  358. /// </summary>
  359. R,
  360. /// <summary>
  361. /// The <see cref="Keyboard.sKey"/>.
  362. /// </summary>
  363. S,
  364. /// <summary>
  365. /// The <see cref="Keyboard.tKey"/>.
  366. /// </summary>
  367. T,
  368. /// <summary>
  369. /// The <see cref="Keyboard.uKey"/>.
  370. /// </summary>
  371. U,
  372. /// <summary>
  373. /// The <see cref="Keyboard.vKey"/>.
  374. /// </summary>
  375. V,
  376. /// <summary>
  377. /// The <see cref="Keyboard.wKey"/>.
  378. /// </summary>
  379. W,
  380. /// <summary>
  381. /// The <see cref="Keyboard.xKey"/>.
  382. /// </summary>
  383. X,
  384. /// <summary>
  385. /// The <see cref="Keyboard.yKey"/>.
  386. /// </summary>
  387. Y,
  388. /// <summary>
  389. /// The <see cref="Keyboard.zKey"/>.
  390. /// </summary>
  391. Z,
  392. /// <summary>
  393. /// The <see cref="Keyboard.digit1Key"/>.
  394. /// </summary>
  395. Digit1,
  396. /// <summary>
  397. /// The <see cref="Keyboard.digit2Key"/>.
  398. /// </summary>
  399. Digit2,
  400. /// <summary>
  401. /// The <see cref="Keyboard.digit3Key"/>.
  402. /// </summary>
  403. Digit3,
  404. /// <summary>
  405. /// The <see cref="Keyboard.digit4Key"/>.
  406. /// </summary>
  407. Digit4,
  408. /// <summary>
  409. /// The <see cref="Keyboard.digit5Key"/>.
  410. /// </summary>
  411. Digit5,
  412. /// <summary>
  413. /// The <see cref="Keyboard.digit6Key"/>.
  414. /// </summary>
  415. Digit6,
  416. /// <summary>
  417. /// The <see cref="Keyboard.digit7Key"/>.
  418. /// </summary>
  419. Digit7,
  420. /// <summary>
  421. /// The <see cref="Keyboard.digit8Key"/>.
  422. /// </summary>
  423. Digit8,
  424. /// <summary>
  425. /// The <see cref="Keyboard.digit9Key"/>.
  426. /// </summary>
  427. Digit9,
  428. /// <summary>
  429. /// The <see cref="Keyboard.digit0Key"/>.
  430. /// </summary>
  431. Digit0,
  432. // ---- Non-printable keys ----
  433. // NOTE: The left&right variants for shift, ctrl, and alt must be next to each other.
  434. /// <summary>
  435. /// The <see cref="Keyboard.leftShiftKey"/>.
  436. /// </summary>
  437. LeftShift,
  438. /// <summary>
  439. /// The <see cref="Keyboard.rightShiftKey"/>.
  440. /// </summary>
  441. RightShift,
  442. /// <summary>
  443. /// The <see cref="Keyboard.leftAltKey"/>.
  444. /// </summary>
  445. LeftAlt,
  446. /// <summary>
  447. /// The <see cref="Keyboard.rightAltKey"/>.
  448. /// </summary>
  449. RightAlt,
  450. /// <summary>
  451. /// Same as <see cref="RightAlt"/>.
  452. /// </summary>
  453. AltGr = RightAlt,
  454. /// <summary>
  455. /// The <see cref="Keyboard.leftCtrlKey"/>.
  456. /// </summary>
  457. LeftCtrl,
  458. /// <summary>
  459. /// The <see cref="Keyboard.rightCtrlKey"/>.
  460. /// </summary>
  461. RightCtrl,
  462. /// <summary>
  463. /// The <see cref="Keyboard.leftMetaKey"/>.
  464. /// </summary>
  465. LeftMeta,
  466. /// <summary>
  467. /// The <see cref="Keyboard.rightMetaKey"/>.
  468. /// </summary>
  469. RightMeta,
  470. /// <summary>
  471. /// Same as <see cref="LeftMeta"/>.
  472. /// </summary>
  473. LeftWindows = LeftMeta,
  474. /// <summary>
  475. /// Same as <see cref="RightMeta"/>.
  476. /// </summary>
  477. RightWindows = RightMeta,
  478. /// <summary>
  479. /// Same as <see cref="LeftMeta"/>.
  480. /// </summary>
  481. LeftApple = LeftMeta,
  482. /// <summary>
  483. /// Same as <see cref="RightMeta"/>.
  484. /// </summary>
  485. RightApple = RightMeta,
  486. /// <summary>
  487. /// Same as <see cref="LeftMeta"/>.
  488. /// </summary>
  489. LeftCommand = LeftMeta,
  490. /// <summary>
  491. /// Same as <see cref="RightMeta"/>.
  492. /// </summary>
  493. RightCommand = RightMeta,
  494. /// <summary>
  495. /// The <see cref="Keyboard.contextMenuKey"/>.
  496. /// </summary>
  497. ContextMenu,
  498. /// <summary>
  499. /// The <see cref="Keyboard.escapeKey"/>.
  500. /// </summary>
  501. Escape,
  502. /// <summary>
  503. /// The <see cref="Keyboard.leftArrowKey"/>.
  504. /// </summary>
  505. LeftArrow,
  506. /// <summary>
  507. /// The <see cref="Keyboard.rightArrowKey"/>.
  508. /// </summary>
  509. RightArrow,
  510. /// <summary>
  511. /// The <see cref="Keyboard.upArrowKey"/>.
  512. /// </summary>
  513. UpArrow,
  514. /// <summary>
  515. /// The <see cref="Keyboard.downArrowKey"/>.
  516. /// </summary>
  517. DownArrow,
  518. /// <summary>
  519. /// The <see cref="Keyboard.backspaceKey"/>.
  520. /// </summary>
  521. Backspace,
  522. /// <summary>
  523. /// The <see cref="Keyboard.pageDownKey"/>.
  524. /// </summary>
  525. PageDown,
  526. /// <summary>
  527. /// The <see cref="Keyboard.pageUpKey"/>.
  528. /// </summary>
  529. PageUp,
  530. /// <summary>
  531. /// The <see cref="Keyboard.homeKey"/>.
  532. /// </summary>
  533. Home,
  534. /// <summary>
  535. /// The <see cref="Keyboard.endKey"/>.
  536. /// </summary>
  537. End,
  538. /// <summary>
  539. /// The <see cref="Keyboard.insertKey"/>.
  540. /// </summary>
  541. Insert,
  542. /// <summary>
  543. /// The <see cref="Keyboard.deleteKey"/>.
  544. /// </summary>
  545. Delete,
  546. /// <summary>
  547. /// The <see cref="Keyboard.capsLockKey"/>.
  548. /// </summary>
  549. CapsLock,
  550. /// <summary>
  551. /// The <see cref="Keyboard.numLockKey"/>.
  552. /// </summary>
  553. NumLock,
  554. /// <summary>
  555. /// The <see cref="Keyboard.printScreenKey"/>.
  556. /// </summary>
  557. PrintScreen,
  558. /// <summary>
  559. /// The <see cref="Keyboard.scrollLockKey"/>.
  560. /// </summary>
  561. ScrollLock,
  562. /// <summary>
  563. /// The <see cref="Keyboard.pauseKey"/>.
  564. /// </summary>
  565. Pause,
  566. // ---- Numpad ----
  567. // NOTE: Numpad layout follows the 18-key numpad layout. Some PC keyboards
  568. // have a 17-key numpad layout where the plus key is an elongated key
  569. // like the numpad enter key. Be aware that in those layouts the positions
  570. // of some of the operator keys are also different. However, we stay
  571. // layout neutral here, too, and always use the 18-key blueprint.
  572. /// <summary>
  573. /// The <see cref="Keyboard.numpadEnterKey"/>.
  574. /// </summary>
  575. NumpadEnter,
  576. /// <summary>
  577. /// The <see cref="Keyboard.numpadDivideKey"/>.
  578. /// </summary>
  579. NumpadDivide,
  580. /// <summary>
  581. /// The <see cref="Keyboard.numpadMultiplyKey"/>.
  582. /// </summary>
  583. NumpadMultiply,
  584. /// <summary>
  585. /// The <see cref="Keyboard.numpadPlusKey"/>.
  586. /// </summary>
  587. NumpadPlus,
  588. /// <summary>
  589. /// The <see cref="Keyboard.numpadMinusKey"/>.
  590. /// </summary>
  591. NumpadMinus,
  592. /// <summary>
  593. /// The <see cref="Keyboard.numpadPeriodKey"/>.
  594. /// </summary>
  595. NumpadPeriod,
  596. /// <summary>
  597. /// The <see cref="Keyboard.numpadEqualsKey"/>.
  598. /// </summary>
  599. NumpadEquals,
  600. /// <summary>
  601. /// The <see cref="Keyboard.numpad0Key"/>.
  602. /// </summary>
  603. Numpad0,
  604. /// <summary>
  605. /// The <see cref="Keyboard.numpad1Key"/>.
  606. /// </summary>
  607. Numpad1,
  608. /// <summary>
  609. /// The <see cref="Keyboard.numpad2Key"/>.
  610. /// </summary>
  611. Numpad2,
  612. /// <summary>
  613. /// The <see cref="Keyboard.numpad3Key"/>.
  614. /// </summary>
  615. Numpad3,
  616. /// <summary>
  617. /// The <see cref="Keyboard.numpad4Key"/>.
  618. /// </summary>
  619. Numpad4,
  620. /// <summary>
  621. /// The <see cref="Keyboard.numpad5Key"/>.
  622. /// </summary>
  623. Numpad5,
  624. /// <summary>
  625. /// The <see cref="Keyboard.numpad6Key"/>.
  626. /// </summary>
  627. Numpad6,
  628. /// <summary>
  629. /// The <see cref="Keyboard.numpad7Key"/>.
  630. /// </summary>
  631. Numpad7,
  632. /// <summary>
  633. /// The <see cref="Keyboard.numpad8Key"/>.
  634. /// </summary>
  635. Numpad8,
  636. /// <summary>
  637. /// The <see cref="Keyboard.numpad9Key"/>.
  638. /// </summary>
  639. Numpad9,
  640. /// <summary>
  641. /// The <see cref="Keyboard.f1Key"/>.
  642. /// </summary>
  643. F1,
  644. /// <summary>
  645. /// The <see cref="Keyboard.f2Key"/>.
  646. /// </summary>
  647. F2,
  648. /// <summary>
  649. /// The <see cref="Keyboard.f3Key"/>.
  650. /// </summary>
  651. F3,
  652. /// <summary>
  653. /// The <see cref="Keyboard.f4Key"/>.
  654. /// </summary>
  655. F4,
  656. /// <summary>
  657. /// The <see cref="Keyboard.f5Key"/>.
  658. /// </summary>
  659. F5,
  660. /// <summary>
  661. /// The <see cref="Keyboard.f6Key"/>.
  662. /// </summary>
  663. F6,
  664. /// <summary>
  665. /// The <see cref="Keyboard.f7Key"/>.
  666. /// </summary>
  667. F7,
  668. /// <summary>
  669. /// The <see cref="Keyboard.f8Key"/>.
  670. /// </summary>
  671. F8,
  672. /// <summary>
  673. /// The <see cref="Keyboard.f9Key"/>.
  674. /// </summary>
  675. F9,
  676. /// <summary>
  677. /// The <see cref="Keyboard.f10Key"/>.
  678. /// </summary>
  679. F10,
  680. /// <summary>
  681. /// The <see cref="Keyboard.f11Key"/>.
  682. /// </summary>
  683. F11,
  684. /// <summary>
  685. /// The <see cref="Keyboard.f12Key"/>.
  686. /// </summary>
  687. F12,
  688. // Extra keys that a keyboard may have. We make no guarantees about where
  689. // they end up on the keyboard (if they are present).
  690. /// <summary>
  691. /// The <see cref="Keyboard.oem1Key"/>.
  692. /// </summary>
  693. OEM1,
  694. /// <summary>
  695. /// The <see cref="Keyboard.oem2Key"/>.
  696. /// </summary>
  697. OEM2,
  698. /// <summary>
  699. /// The <see cref="Keyboard.oem3Key"/>.
  700. /// </summary>
  701. OEM3,
  702. /// <summary>
  703. /// The <see cref="Keyboard.oem4Key"/>.
  704. /// </summary>
  705. OEM4,
  706. /// <summary>
  707. /// The <see cref="Keyboard.oem5Key"/>.
  708. /// </summary>
  709. OEM5,
  710. ////FIXME: This should never have been a Key but rather just an extra button or state on keyboard
  711. // Not exactly a key, but binary data sent by the Keyboard to say if IME is being used.
  712. IMESelected
  713. }
  714. /// <summary>
  715. /// Represents a standard, physical PC-type keyboard.
  716. /// </summary>
  717. /// <remarks>
  718. /// Keyboards allow for both individual button input as well as text input. To receive button
  719. /// input, use the individual <see cref="KeyControl"/>-type controls present on the keyboard.
  720. /// For example, <see cref="aKey"/>. To receive text input, use the <see cref="onTextInput"/>
  721. /// callback.
  722. ///
  723. /// The naming/identification of keys is agnostic to keyboard layouts. This means that <see cref="aKey"/>,
  724. /// for example, will always be the key to the right of <see cref="capsLockKey"/> regardless of where
  725. /// the current keyboard language layout puts the "a" character. This also means that having a
  726. /// binding to <c>"&lt;Keyboard&gt;/a"</c> on an <see cref="InputAction"/>, for example, will
  727. /// bind to the same key regardless of locale -- an important feature, for example, for getting
  728. /// stable WASD bindings.
  729. ///
  730. /// To find what text character (if any) is produced by a key, you can use the key's <see
  731. /// cref="InputControl.displayName"/> property. This can also be used in bindings.
  732. /// <c>"&lt;Keyboard&gt;/#(a)"</c>, for example, will bind to the key that produces the "a"
  733. /// character according to the currently active keyboard layout.
  734. ///
  735. /// To find out which keyboard layout is currently active, you can use the <see cref="keyboardLayout"/>
  736. /// property. Note that keyboard layout names are platform-dependent.
  737. ///
  738. /// Note that keyboard devices will always have key controls added for all keys in the
  739. /// <see cref="Key"/> enumeration -- whether they are actually present on the physical
  740. /// keyboard or not. It is thus not possible to find out this way whether the underlying
  741. /// keyboard has certain keys or not.
  742. /// </remarks>
  743. [InputControlLayout(stateType = typeof(KeyboardState), isGenericTypeOfDevice = true)]
  744. public class Keyboard : InputDevice, ITextInputReceiver
  745. {
  746. /// <summary>
  747. /// Total number of key controls on a keyboard, i.e. the number of controls
  748. /// in <see cref="allKeys"/>.
  749. /// </summary>
  750. /// <value>Total number of key controls.</value>
  751. public const int KeyCount = (int)Key.OEM5;
  752. /// <summary>
  753. /// Event that is fired for every single character entered on the keyboard.
  754. /// </summary>
  755. /// <value>Triggered whenever the keyboard receives text input.</value>
  756. /// <remarks>
  757. /// <example>
  758. /// <code>
  759. /// // Let's say we want to do a typing game. We could define a component
  760. /// // something along those lines to match the typed input.
  761. /// public class MatchTextByTyping : MonoBehaviour
  762. /// {
  763. /// public string text
  764. /// {
  765. /// get => m_Text;
  766. /// set
  767. /// {
  768. /// m_Text = value;
  769. /// m_Position = 0;
  770. /// }
  771. /// }
  772. ///
  773. /// public Action onTextTypedCorrectly { get; set; }
  774. /// public Action onTextTypedIncorrectly { get; set; }
  775. ///
  776. /// private int m_Position;
  777. /// private string m_Text;
  778. ///
  779. /// protected void OnEnable()
  780. /// {
  781. /// Keyboard.current.onTextInput += OnTextInput;
  782. /// }
  783. ///
  784. /// protected void OnDisable()
  785. /// {
  786. /// Keyboard.current.onTextInput -= OnTextInput;
  787. /// }
  788. ///
  789. /// private void OnTextInput(char ch)
  790. /// {
  791. /// if (m_Text == null || m_Position >= m_Text.Length)
  792. /// return;
  793. ///
  794. /// if (m_Text[m_Position] == ch)
  795. /// {
  796. /// ++m_Position;
  797. /// if (m_Position == m_Text.Length)
  798. /// onTextTypeCorrectly?.Invoke();
  799. /// }
  800. /// else
  801. /// {
  802. /// m_Text = null;
  803. /// m_Position = 0;
  804. ///
  805. /// onTextTypedIncorrectly?.Invoke();
  806. /// }
  807. /// }
  808. /// }
  809. /// </code>
  810. /// </example>
  811. /// </remarks>
  812. public event Action<char> onTextInput
  813. {
  814. add
  815. {
  816. if (value == null)
  817. throw new ArgumentNullException(nameof(value));
  818. if (!m_TextInputListeners.Contains(value))
  819. m_TextInputListeners.Append(value);
  820. }
  821. remove => m_TextInputListeners.Remove(value);
  822. }
  823. /// <summary>
  824. /// An event that is fired to get IME composition strings. Fired once for every change containing the entire string to date.
  825. /// When using an IME, this event can be used to display the composition string while it is being edited. When a composition
  826. /// string is submitted, one or many <see cref="Keyboard.OnTextInput"/> events will fire with the submitted characters.
  827. /// </summary>
  828. /// <remarks>
  829. /// Some languages use complex input methods which involve opening windows to insert characters.
  830. /// Typically, this is not desirable while playing a game, as games may just interpret key strokes as game input, not as text.
  831. ///
  832. /// Many IMEs cause this event to fire with a blank string when the composition is submitted or reset, however it is best
  833. /// not to rely on this behaviour since it is IME dependent.
  834. ///
  835. /// See <see cref="Keyboard.SetIMEEnabled"/> for turning IME on/off
  836. /// </remarks>
  837. public event Action<IMECompositionString> onIMECompositionChange
  838. {
  839. add
  840. {
  841. if (value == null)
  842. throw new ArgumentNullException(nameof(value));
  843. if (!m_ImeCompositionListeners.Contains(value))
  844. m_ImeCompositionListeners.Append(value);
  845. }
  846. remove => m_ImeCompositionListeners.Remove(value);
  847. }
  848. /// <summary>
  849. /// Activates/deactivates IME composition while typing. This decides whether or not to use the OS supplied IME system.
  850. /// </summary>
  851. /// <remarks>
  852. ///
  853. /// Some languages use complex input methods which involve opening windows to insert characters.
  854. /// Typically, this is not desirable while playing a game, as games may just interpret key strokes as game input, not as text.
  855. /// Setting this to On, will enable the OS-level IME system when the user presses keystrokes.
  856. ///
  857. /// See <see cref="Keyboard.SetIMECursorPosition"/>, <see cref="Keyboard.onIMECompositionChange"/>,
  858. /// <see cref="Keyboard.imeSelected"/> for more IME settings and data.
  859. /// </remarks>
  860. public void SetIMEEnabled(bool enabled)
  861. {
  862. var command = EnableIMECompositionCommand.Create(enabled);
  863. ExecuteCommand(ref command);
  864. }
  865. /// <summary>
  866. /// Sets the cursor position for IME composition dialogs. Units are from the upper left, in pixels, moving down and to the right.
  867. /// </summary>
  868. /// <remarks>
  869. /// Some languages use complex input methods which involve opening windows to insert characters.
  870. /// Typically, this is not desirable while playing a game, as games may just interpret key strokes as game input, not as text.
  871. ///
  872. /// See <see cref="Keyboard.SetIMEEnabled"/> for turning IME on/off
  873. /// </remarks>
  874. public void SetIMECursorPosition(Vector2 position)
  875. {
  876. SetIMECursorPositionCommand command = SetIMECursorPositionCommand.Create(position);
  877. ExecuteCommand(ref command);
  878. }
  879. /// <summary>
  880. /// The name of the layout currently used by the keyboard.
  881. /// </summary>
  882. /// <remarks>
  883. /// Note that keyboard layout names are platform-specific.
  884. ///
  885. /// The value of this property reflects the currently used layout and thus changes
  886. /// whenever the layout of the system or the one for the application is changed.
  887. ///
  888. /// To determine what a key represents in the current layout, use <see cref="InputControl.displayName"/>.
  889. /// </remarks>
  890. public string keyboardLayout
  891. {
  892. get
  893. {
  894. RefreshConfigurationIfNeeded();
  895. return m_KeyboardLayoutName;
  896. }
  897. protected set => m_KeyboardLayoutName = value;
  898. }
  899. /// <summary>
  900. /// A synthetic button control that is considered pressed if any key on the keyboard is pressed.
  901. /// </summary>
  902. /// <value>Control representing the synthetic "anyKey".</value>
  903. public AnyKeyControl anyKey { get; protected set; }
  904. /// <summary>
  905. /// The space bar key.
  906. /// </summary>
  907. /// <value>Control representing the space bar key.</value>
  908. public KeyControl spaceKey => this[Key.Space];
  909. /// <summary>
  910. /// The enter/return key in the main key block.
  911. /// </summary>
  912. /// <value>Control representing the enter key.</value>
  913. /// <remarks>
  914. /// This key is distinct from the enter key on the numpad which is <see cref="numpadEnterKey"/>.
  915. /// </remarks>
  916. public KeyControl enterKey => this[Key.Enter];
  917. /// <summary>
  918. /// The tab key.
  919. /// </summary>
  920. /// <value>Control representing the tab key.</value>
  921. public KeyControl tabKey => this[Key.Tab];
  922. /// <summary>
  923. /// The ` key. The leftmost key in the row of digits. Directly above <see cref="tabKey"/>.
  924. /// </summary>
  925. /// <value>Control representing the backtick/quote key.</value>
  926. public KeyControl backquoteKey => this[Key.Backquote];
  927. /// <summary>
  928. /// The ' key. The key immediately to the left of <see cref="enterKey"/>.
  929. /// </summary>
  930. /// <value>Control representing the quote key.</value>
  931. public KeyControl quoteKey => this[Key.Quote];
  932. /// <summary>
  933. /// The ';' key. The key immediately to the left of <see cref="quoteKey"/>.
  934. /// </summary>
  935. /// <value>Control representing the semicolon key.</value>
  936. public KeyControl semicolonKey => this[Key.Semicolon];
  937. /// <summary>
  938. /// The ',' key. Third key to the left of <see cref="rightShiftKey"/>.
  939. /// </summary>
  940. /// <value>Control representing the comma key.</value>
  941. public KeyControl commaKey => this[Key.Comma];
  942. /// <summary>
  943. /// The '.' key. Second key to the left of <see cref="rightShiftKey"/>.
  944. /// </summary>
  945. /// <value>Control representing the period key.</value>
  946. public KeyControl periodKey => this[Key.Period];
  947. /// <summary>
  948. /// The '/' key. The key immediately to the left of <see cref="rightShiftKey"/>.
  949. /// </summary>
  950. /// <value>Control representing the forward slash key.</value>
  951. public KeyControl slashKey => this[Key.Slash];
  952. /// <summary>
  953. /// The '\' key. The key immediately to the right of <see cref="rightBracketKey"/> and
  954. /// next to or above <see cref="enterKey"/>.
  955. /// </summary>
  956. /// <value>Control representing the backslash key.</value>
  957. public KeyControl backslashKey => this[Key.Backslash];
  958. /// <summary>
  959. /// The '[' key. The key immediately to the left of <see cref="rightBracketKey"/>.
  960. /// </summary>
  961. /// <value>Control representing the left bracket key.</value>
  962. public KeyControl leftBracketKey => this[Key.LeftBracket];
  963. /// <summary>
  964. /// The ']' key. The key in-between <see cref="leftBracketKey"/> to the left and
  965. /// <see cref="backslashKey"/> to the right.
  966. /// </summary>
  967. /// <value>Control representing the right bracket key.</value>
  968. public KeyControl rightBracketKey => this[Key.RightBracket];
  969. /// <summary>
  970. /// The '-' key. The second key to the left of <see cref="backspaceKey"/>.
  971. /// </summary>
  972. /// <value>Control representing the minus key.</value>
  973. public KeyControl minusKey => this[Key.Minus];
  974. /// <summary>
  975. /// The '=' key in the main key block. The key in-between <see cref="minusKey"/> to the left
  976. /// and <see cref="backspaceKey"/> to the right.
  977. /// </summary>
  978. /// <value>Control representing the equals key.</value>
  979. public KeyControl equalsKey => this[Key.Equals];
  980. /// <summary>
  981. /// The 'a' key. The key immediately to the right of <see cref="capsLockKey"/>.
  982. /// </summary>
  983. /// <value>Control representing the a key.</value>
  984. public KeyControl aKey => this[Key.A];
  985. /// <summary>
  986. /// The 'b' key. The key in-between the <see cref="vKey"/> to the left and the <see cref="nKey"/>
  987. /// to the right in the bottom-most row of alphabetic characters.
  988. /// </summary>
  989. /// <value>Control representing the b key.</value>
  990. public KeyControl bKey => this[Key.B];
  991. /// <summary>
  992. /// The 'c' key. The key in-between the <see cref="xKey"/> to the left and the <see cref="vKey"/>
  993. /// to the right in the bottom-most row of alphabetic characters.
  994. /// </summary>
  995. /// <value>Control representing the c key.</value>
  996. public KeyControl cKey => this[Key.C];
  997. /// <summary>
  998. /// The 'd' key. The key in-between the <see cref="sKey"/> to the left and the <see cref="fKey"/>
  999. /// to the right in the middle row of alphabetic characters.
  1000. /// </summary>
  1001. /// <value>Control representing the d key.</value>
  1002. public KeyControl dKey => this[Key.D];
  1003. /// <summary>
  1004. /// The 'e' key. The key in-between the <see cref="wKey"/> to the left and the <see cref="rKey"/>
  1005. /// to the right in the topmost row of alphabetic characters.
  1006. /// </summary>
  1007. /// <value>Control representing the e key.</value>
  1008. public KeyControl eKey => this[Key.E];
  1009. /// <summary>
  1010. /// The 'f' key. The key in-between the <see cref="dKey"/> to the left and the <see cref="gKey"/>
  1011. /// to the right in the middle row of alphabetic characters.
  1012. /// </summary>
  1013. /// <value>Control representing the f key.</value>
  1014. public KeyControl fKey => this[Key.F];
  1015. /// <summary>
  1016. /// The 'g' key. The key in-between the <see cref="fKey"/> to the left and the <see cref="hKey"/>
  1017. /// to the right in the middle row of alphabetic characters.
  1018. /// </summary>
  1019. /// <value>Control representing the g key.</value>
  1020. public KeyControl gKey => this[Key.G];
  1021. /// <summary>
  1022. /// The 'h' key. The key in-between the <see cref="gKey"/> to the left and the <see cref="jKey"/>
  1023. /// to the right in the middle row of alphabetic characters.
  1024. /// </summary>
  1025. /// <value>Control representing the h key.</value>
  1026. public KeyControl hKey => this[Key.H];
  1027. /// <summary>
  1028. /// The 'i' key. The key in-between the <see cref="uKey"/> to the left and the <see cref="oKey"/>
  1029. /// to the right in the top row of alphabetic characters.
  1030. /// </summary>
  1031. public KeyControl iKey => this[Key.I];
  1032. /// <summary>
  1033. /// The 'j' key. The key in-between the <see cref="hKey"/> to the left and the <see cref="kKey"/>
  1034. /// to the right in the middle row of alphabetic characters.
  1035. /// </summary>
  1036. /// <value>Control representing the j key.</value>
  1037. public KeyControl jKey => this[Key.J];
  1038. /// <summary>
  1039. /// The 'k' key. The key in-between the <see cref="jKey"/> to the left and the <see cref="lKey"/>
  1040. /// to the right in the middle row of alphabetic characters.
  1041. /// </summary>
  1042. /// <value>Control representing the k key.</value>
  1043. public KeyControl kKey => this[Key.K];
  1044. /// <summary>
  1045. /// The 'l' key. The key in-between the <see cref="kKey"/> to the left and the <see cref="semicolonKey"/>
  1046. /// to the right in the middle row of alphabetic characters.
  1047. /// </summary>
  1048. /// <value>Control representing the l key.</value>
  1049. public KeyControl lKey => this[Key.L];
  1050. /// <summary>
  1051. /// The 'm' key. The key in-between the <see cref="nKey"/> to the left and the <see cref="commaKey"/>
  1052. /// to the right in the bottom row of alphabetic characters.
  1053. /// </summary>
  1054. /// <value>Control representing the m key.</value>
  1055. public KeyControl mKey => this[Key.M];
  1056. /// <summary>
  1057. /// The 'n' key. The key in-between the <see cref="bKey"/> to the left and the <see cref="mKey"/> to
  1058. /// the right in the bottom row of alphabetic characters.
  1059. /// </summary>
  1060. /// <value>Control representing the n key.</value>
  1061. public KeyControl nKey => this[Key.N];
  1062. /// <summary>
  1063. /// The 'o' key. The key in-between the <see cref="iKey"/> to the left and the <see cref="pKey"/> to
  1064. /// the right in the top row of alphabetic characters.
  1065. /// </summary>
  1066. /// <value>Control representing the o key.</value>
  1067. public KeyControl oKey => this[Key.O];
  1068. /// <summary>
  1069. /// The 'p' key. The key in-between the <see cref="oKey"/> to the left and the <see cref="leftBracketKey"/>
  1070. /// to the right in the top row of alphabetic characters.
  1071. /// </summary>
  1072. /// <value>Control representing the p key.</value>
  1073. public KeyControl pKey => this[Key.P];
  1074. /// <summary>
  1075. /// The 'q' key. The key in-between the <see cref="tabKey"/> to the left and the <see cref="wKey"/>
  1076. /// to the right in the top row of alphabetic characters.
  1077. /// </summary>
  1078. /// <value>Control representing the q key.</value>
  1079. public KeyControl qKey => this[Key.Q];
  1080. /// <summary>
  1081. /// The 'r' key. The key in-between the <see cref="eKey"/> to the left and the <see cref="tKey"/>
  1082. /// to the right in the top row of alphabetic characters.
  1083. /// </summary>
  1084. /// <value>Control representing the r key.</value>
  1085. public KeyControl rKey => this[Key.R];
  1086. /// <summary>
  1087. /// The 's' key. The key in-between the <see cref="aKey"/> to the left and the <see cref="dKey"/>
  1088. /// to the right in the middle row of alphabetic characters.
  1089. /// </summary>
  1090. /// <value>Control representing the s key.</value>
  1091. public KeyControl sKey => this[Key.S];
  1092. /// <summary>
  1093. /// The 't' key. The key in-between the <see cref="rKey"/> to the left and the <see cref="yKey"/>
  1094. /// to the right in the top row of alphabetic characters.
  1095. /// </summary>
  1096. /// <value>Control representing the t key.</value>
  1097. public KeyControl tKey => this[Key.T];
  1098. /// <summary>
  1099. /// The 'u' key. The key in-between the <see cref="yKey"/> to the left and the <see cref="iKey"/>
  1100. /// to the right in the top row of alphabetic characters.
  1101. /// </summary>
  1102. /// <value>Control representing the u key.</value>
  1103. public KeyControl uKey => this[Key.U];
  1104. /// <summary>
  1105. /// The 'v' key. The key in-between the <see cref="cKey"/> to the left and the <see cref="bKey"/>
  1106. /// to the right in the bottom row of alphabetic characters.
  1107. /// </summary>
  1108. /// <value>Control representing the v key.</value>
  1109. public KeyControl vKey => this[Key.V];
  1110. /// <summary>
  1111. /// The 'w' key. The key in-between the <see cref="qKey"/> to the left and the <see cref="eKey"/>
  1112. /// to the right in the top row of alphabetic characters.
  1113. /// </summary>
  1114. /// <value>Control representing the w key.</value>
  1115. public KeyControl wKey => this[Key.W];
  1116. /// <summary>
  1117. /// The 'x' key. The key in-between the <see cref="zKey"/> to the left and the <see cref="cKey"/>
  1118. /// to the right in the bottom row of alphabetic characters.
  1119. /// </summary>
  1120. /// <value>Control representing the x key.</value>
  1121. public KeyControl xKey => this[Key.X];
  1122. /// <summary>
  1123. /// The 'y' key. The key in-between the <see cref="tKey"/> to the left and the <see cref="uKey"/>
  1124. /// to the right in the top row of alphabetic characters.
  1125. /// </summary>
  1126. /// <value>Control representing the y key.</value>
  1127. public KeyControl yKey => this[Key.Y];
  1128. /// <summary>
  1129. /// The 'z' key. The key in-between the <see cref="leftShiftKey"/> to the left and the <see cref="xKey"/>
  1130. /// to the right in the bottom row of alphabetic characters.
  1131. /// </summary>
  1132. /// <value>Control representing the z key.</value>
  1133. public KeyControl zKey => this[Key.Z];
  1134. /// <summary>
  1135. /// The '1' key. The key in-between the <see cref="backquoteKey"/> to the left and the <see cref="digit2Key"/>
  1136. /// to the right in the row of digit characters.
  1137. /// </summary>
  1138. /// <value>Control representing the 1 key.</value>
  1139. public KeyControl digit1Key => this[Key.Digit1];
  1140. /// <summary>
  1141. /// The '2' key. The key in-between the <see cref="digit1Key"/> to the left and the <see cref="digit3Key"/>
  1142. /// to the right in the row of digit characters.
  1143. /// </summary>
  1144. /// <value>Control representing the 2 key.</value>
  1145. public KeyControl digit2Key => this[Key.Digit2];
  1146. /// <summary>
  1147. /// The '3' key. The key in-between the <see cref="digit2Key"/> to the left and the <see cref="digit4Key"/>
  1148. /// to the right in the row of digit characters.
  1149. /// </summary>
  1150. /// <value>Control representing the 3 key.</value>
  1151. public KeyControl digit3Key => this[Key.Digit3];
  1152. /// <summary>
  1153. /// The '4' key. The key in-between the <see cref="digit3Key"/> to the left and the <see cref="digit5Key"/>
  1154. /// to the right in the row of digit characters.
  1155. /// </summary>
  1156. /// <value>Control representing the 4 key.</value>
  1157. public KeyControl digit4Key => this[Key.Digit4];
  1158. /// <summary>
  1159. /// The '5' key. The key in-between the <see cref="digit4Key"/> to the left and the <see cref="digit6Key"/>
  1160. /// to the right in the row of digit characters.
  1161. /// </summary>
  1162. /// <value>Control representing the 5 key.</value>
  1163. public KeyControl digit5Key => this[Key.Digit5];
  1164. /// <summary>
  1165. /// The '6' key. The key in-between the <see cref="digit5Key"/> to the left and the <see cref="digit7Key"/>
  1166. /// to the right in the row of digit characters.
  1167. /// </summary>
  1168. /// <value>Control representing the 6 key.</value>
  1169. public KeyControl digit6Key => this[Key.Digit6];
  1170. /// <summary>
  1171. /// The '7' key. The key in-between the <see cref="digit6Key"/> to the left and the <see cref="digit8Key"/>
  1172. /// to the right in the row of digit characters.
  1173. /// </summary>
  1174. /// <value>Control representing the 7 key.</value>
  1175. public KeyControl digit7Key => this[Key.Digit7];
  1176. /// <summary>
  1177. /// The '8' key. The key in-between the <see cref="digit7Key"/> to the left and the <see cref="digit9Key"/>
  1178. /// to the right in the row of digit characters.
  1179. /// </summary>
  1180. /// <value>Control representing the 8 key.</value>
  1181. public KeyControl digit8Key => this[Key.Digit8];
  1182. /// <summary>
  1183. /// The '9' key. The key in-between the <see cref="digit8Key"/> to the left and the <see cref="digit0Key"/>
  1184. /// to the right in the row of digit characters.
  1185. /// </summary>
  1186. /// <value>Control representing the 9 key.</value>
  1187. public KeyControl digit9Key => this[Key.Digit9];
  1188. /// <summary>
  1189. /// The '0' key. The key in-between the <see cref="digit9Key"/> to the left and the <see cref="minusKey"/>
  1190. /// to the right in the row of digit characters.
  1191. /// </summary>
  1192. /// <value>Control representing the 0 key.</value>
  1193. public KeyControl digit0Key => this[Key.Digit0];
  1194. /// <summary>
  1195. /// The shift key on the left side of the keyboard.
  1196. /// </summary>
  1197. /// <value>Control representing the left shift key.</value>
  1198. public KeyControl leftShiftKey => this[Key.LeftShift];
  1199. /// <summary>
  1200. /// The shift key on the right side of the keyboard.
  1201. /// </summary>
  1202. /// <value>Control representing the right shift key.</value>
  1203. public KeyControl rightShiftKey => this[Key.RightShift];
  1204. /// <summary>
  1205. /// The alt/option key on the left side of the keyboard.
  1206. /// </summary>
  1207. /// <value>Control representing the left alt/option key.</value>
  1208. public KeyControl leftAltKey => this[Key.LeftAlt];
  1209. /// <summary>
  1210. /// The alt/option key on the right side of the keyboard.
  1211. /// </summary>
  1212. /// <value>Control representing the right alt/option key.</value>
  1213. public KeyControl rightAltKey => this[Key.RightAlt];
  1214. /// <summary>
  1215. /// The control/ctrl key on the left side of the keyboard.
  1216. /// </summary>
  1217. /// <value>Control representing the left control key.</value>
  1218. public KeyControl leftCtrlKey => this[Key.LeftCtrl];
  1219. /// <summary>
  1220. /// The control/ctrl key on the right side of the keyboard.
  1221. /// </summary>
  1222. /// <remarks>This key is usually not present on Mac laptops.</remarks>
  1223. /// <value>Control representing the right control key.</value>
  1224. public KeyControl rightCtrlKey => this[Key.RightCtrl];
  1225. /// <summary>
  1226. /// The system "meta" key (Windows key on PC, Apple/command key on Mac) on the left
  1227. /// side of the keyboard.
  1228. /// </summary>
  1229. /// <value>Control representing the left system meta key.</value>
  1230. public KeyControl leftMetaKey => this[Key.LeftMeta];
  1231. /// <summary>
  1232. /// The system "meta" key (Windows key on PC, Apple/command key on Mac) on the right
  1233. /// side of the keyboard.
  1234. /// </summary>
  1235. /// <value>Control representing the right system meta key.</value>
  1236. public KeyControl rightMetaKey => this[Key.RightMeta];
  1237. /// <summary>
  1238. /// Same as <see cref="leftMetaKey"/>. Windows system key on left side of keyboard.
  1239. /// </summary>
  1240. /// <value>Control representing the left Windows system key.</value>
  1241. public KeyControl leftWindowsKey => this[Key.LeftWindows];
  1242. /// <summary>
  1243. /// Same as <see cref="rightMetaKey"/>. Windows system key on right side of keyboard.
  1244. /// </summary>
  1245. /// <value>Control representing the right Windows system key.</value>
  1246. public KeyControl rightWindowsKey => this[Key.RightWindows];
  1247. /// <summary>
  1248. /// Same as <see cref="leftMetaKey"/>. Apple/command system key on left side of keyboard.
  1249. /// </summary>
  1250. /// <value>Control representing the left Apple/command system key.</value>
  1251. public KeyControl leftAppleKey => this[Key.LeftApple];
  1252. /// <summary>
  1253. /// Same as <see cref="rightMetaKey"/>. Apple/command system key on right side of keyboard.
  1254. /// </summary>
  1255. /// <value>Control representing the right Apple/command system key.</value>
  1256. public KeyControl rightAppleKey => this[Key.RightApple];
  1257. /// <summary>
  1258. /// Same as <see cref="leftMetaKey"/>. Apple/command system key on left side of keyboard.
  1259. /// </summary>
  1260. /// <value>Control representing the left Apple/command system key.</value>
  1261. public KeyControl leftCommandKey => this[Key.LeftCommand];
  1262. /// <summary>
  1263. /// Same as <see cref="rightMetaKey"/>. Apple/command system key on right side of keyboard.
  1264. /// </summary>
  1265. /// <value>Control representing the right Apple/command system key.</value>
  1266. public KeyControl rightCommandKey => this[Key.RightCommand];
  1267. /// <summary>
  1268. /// The context menu key. This key is generally only found on PC keyboards. If present,
  1269. /// the key is found in-between the <see cref="rightWindowsKey"/> to the left and the
  1270. /// <see cref="rightCtrlKey"/> to the right. It's intention is to bring up the context
  1271. /// menu according to the current selection.
  1272. /// </summary>
  1273. /// <value>Control representing the context menu key.</value>
  1274. public KeyControl contextMenuKey => this[Key.ContextMenu];
  1275. /// <summary>
  1276. /// The escape key, i.e. the key generally in the top left corner of the keyboard.
  1277. /// Usually to the left of <see cref="f1Key"/>.
  1278. /// </summary>
  1279. /// <value>Control representing the escape key.</value>
  1280. public KeyControl escapeKey => this[Key.Escape];
  1281. /// <summary>
  1282. /// The left arrow key. Usually in a block by itself and generally to the left
  1283. /// of <see cref="downArrowKey"/>.
  1284. /// </summary>
  1285. /// <value>Control representing the left arrow key.</value>
  1286. public KeyControl leftArrowKey => this[Key.LeftArrow];
  1287. /// <summary>
  1288. /// The right arrow key. Usually in a block by itself and generally to the right
  1289. /// of <see cref="downArrowKey"/>
  1290. /// </summary>
  1291. /// <value>Control representing the right arrow key.</value>
  1292. public KeyControl rightArrowKey => this[Key.RightArrow];
  1293. /// <summary>
  1294. /// The up arrow key. Usually in a block by itself and generally on top of the
  1295. /// <see cref="downArrowKey"/>.
  1296. /// </summary>
  1297. /// <value>Control representing the up arrow key.</value>
  1298. public KeyControl upArrowKey => this[Key.UpArrow];
  1299. /// <summary>
  1300. /// The down arrow key. Usually in a block by itself and generally below the
  1301. /// <see cref="upArrowKey"/> and in-between <see cref="leftArrowKey"/> to the
  1302. /// left and <see cref="rightArrowKey"/> to the right.
  1303. /// </summary>
  1304. /// <value>Control representing the down arrow key.</value>
  1305. public KeyControl downArrowKey => this[Key.DownArrow];
  1306. /// <summary>
  1307. /// The backspace key (usually labeled "delete" on Mac). The rightmost key
  1308. /// in the top digit row with <see cref="equalsKey"/> to the left.
  1309. /// </summary>
  1310. /// <value>Control representing the backspace key.</value>
  1311. /// <remarks>
  1312. /// On the Mac, this key may be labeled "delete" which however is a
  1313. /// key different from <see cref="deleteKey"/>.
  1314. /// </remarks>
  1315. public KeyControl backspaceKey => this[Key.Backspace];
  1316. /// <summary>
  1317. /// The page down key. Usually in a separate block with <see cref="endKey"/>
  1318. /// to the left and <see cref="pageUpKey"/> above it.
  1319. /// </summary>
  1320. /// <value>Control representing the page down key.</value>
  1321. public KeyControl pageDownKey => this[Key.PageDown];
  1322. /// <summary>
  1323. /// The page up key. Usually in a separate block with <see cref="homeKey"/>
  1324. /// to the left and <see cref="pageDownKey"/> below it.
  1325. /// </summary>
  1326. /// <value>Control representing the page up key.</value>
  1327. public KeyControl pageUpKey => this[Key.PageUp];
  1328. /// <summary>
  1329. /// The 'home' key. Usually in a separate block with <see cref="pageUpKey"/>
  1330. /// to the right and <see cref="insertKey"/> to the left.
  1331. /// </summary>
  1332. /// <value>Control representing the insert key.</value>
  1333. public KeyControl homeKey => this[Key.Home];
  1334. /// <summary>
  1335. /// The 'end' key. Usually in a separate block with <see cref="deleteKey"/>
  1336. /// to the left and <see cref="pageDownKey"/> to the right.
  1337. /// </summary>
  1338. /// <value>Control representing the end key.</value>
  1339. public KeyControl endKey => this[Key.End];
  1340. /// <summary>
  1341. /// The 'insert' key. Usually in a separate block with <see cref="homeKey"/>
  1342. /// to its right and <see cref="deleteKey"/> sitting below it.
  1343. /// </summary>
  1344. /// <value>Control representing the insert key.</value>
  1345. public KeyControl insertKey => this[Key.Insert];
  1346. /// <summary>
  1347. /// The 'delete' key. Usually in a separate block with <see cref="endKey"/>
  1348. /// to its right and <see cref="insertKey"/> sitting above it.
  1349. /// </summary>
  1350. /// <value>Control representing the delete key.</value>
  1351. /// <remarks>
  1352. /// On the Mac, the <see cref="backspaceKey"/> is also labeled "delete".
  1353. /// However, this is not this key.
  1354. /// </remarks>
  1355. public KeyControl deleteKey => this[Key.Delete];
  1356. /// <summary>
  1357. /// The Caps Lock key. The key below <see cref="tabKey"/> and above
  1358. /// <see cref="leftShiftKey"/>.
  1359. /// </summary>
  1360. /// <value>Control representing the caps lock key.</value>
  1361. public KeyControl capsLockKey => this[Key.CapsLock];
  1362. /// <summary>
  1363. /// The Scroll Lock key. The key in-between the <see cref="printScreenKey"/>
  1364. /// to the left and the <see cref="pauseKey"/> to the right. May also
  1365. /// be labeled "F14".
  1366. /// </summary>
  1367. /// <value>Control representing the scroll lock key.</value>
  1368. public KeyControl scrollLockKey => this[Key.ScrollLock];
  1369. /// <summary>
  1370. /// The Num Lock key. The key sitting in the top left corner of the
  1371. /// numpad and which usually toggles the numpad between generating
  1372. /// digits and triggering functions like "insert" etc. instead.
  1373. /// </summary>
  1374. /// <value>Control representing the num lock key.</value>
  1375. public KeyControl numLockKey => this[Key.NumLock];
  1376. /// <summary>
  1377. /// The Print Screen key. The key sitting in-between <see cref="f12Key"/>
  1378. /// to the left and <see cref="scrollLockKey"/> to the right. May also
  1379. /// be labeled "F13".
  1380. /// </summary>
  1381. /// <value>Control representing the print screen key.</value>
  1382. public KeyControl printScreenKey => this[Key.PrintScreen];
  1383. /// <summary>
  1384. /// The pause/break key. The key sitting to the left of <see cref="scrollLockKey"/>.
  1385. /// May also be labeled "F15".
  1386. /// </summary>
  1387. /// <value>Control representing the pause/break key.</value>
  1388. public KeyControl pauseKey => this[Key.Pause];
  1389. /// <summary>
  1390. /// The enter key on the numpad. The key sitting in the bottom right corner
  1391. /// of the numpad.
  1392. /// </summary>
  1393. /// <value>Control representing the numpad enter key.</value>
  1394. public KeyControl numpadEnterKey => this[Key.NumpadEnter];
  1395. /// <summary>
  1396. /// The divide ('/') key on the numpad. The key in-between <see cref="numpadEqualsKey"/>
  1397. /// to the left and <see cref="numpadMultiplyKey"/> to the right.
  1398. /// </summary>
  1399. /// <value>Control representing the numpad divide key.</value>
  1400. /// <remarks>
  1401. /// PC keyboards usually have a 17-key numpad layout that differs from the 18-key layout
  1402. /// we use for reference. The 18-key layout is usually found on Mac keyboards. The numpad
  1403. /// divide key usually is the <see cref="numpadEqualsKey"/> on PC keyboards.
  1404. /// </remarks>
  1405. public KeyControl numpadDivideKey => this[Key.NumpadDivide];
  1406. /// <summary>
  1407. /// The multiply ('*') key on the numpad. The key in the upper right corner of the numpad
  1408. /// with <see cref="numpadDivideKey"/> to the left and <see cref="numpadMultiplyKey"/>
  1409. /// below it.
  1410. /// </summary>
  1411. /// <value>Control representing the numpad multiply key.</value>
  1412. /// <remarks>
  1413. /// PC keyboards usually have a 17-key numpad layout that differs from the 18-key layout
  1414. /// we use for reference. The 18-key layout is usually found on Mac keyboards. The numpad
  1415. /// multiply key usually is the <see cref="numpadMinusKey"/> on PC keyboards.
  1416. /// </remarks>
  1417. public KeyControl numpadMultiplyKey => this[Key.NumpadMultiply];
  1418. /// <summary>
  1419. /// The minus ('-') key on the numpad. The key on the right side of the numpad with
  1420. /// <see cref="numpadMultiplyKey"/> above it and <see cref="numpadPlusKey"/> below it.
  1421. /// </summary>
  1422. /// <value>Control representing the numpad minus key.</value>
  1423. /// <remarks>
  1424. /// PC keyboards usually have a 17-key numpad layout that differs from the 18-key layout
  1425. /// we use for reference. The 18-key layout is usually found on Mac keyboards. The numpad
  1426. /// minus key is usually <em>not</em> present on PC keyboards. Instead, the 17-key layout
  1427. /// has an elongated <see cref="numpadPlusKey"/> that covers the space of two keys.
  1428. /// </remarks>
  1429. public KeyControl numpadMinusKey => this[Key.NumpadMinus];
  1430. /// <summary>
  1431. /// The plus ('+') key on the numpad. The key on the right side of the numpad with
  1432. /// <see cref="numpadMinusKey"/> above it and <see cref="numpadEnterKey"/> below it.
  1433. /// </summary>
  1434. /// <value>Control representing the numpad plus key.</value>
  1435. /// <remarks>
  1436. /// PC keyboards usually have a 17-key numpad layout that differs from the 18-key layout
  1437. /// we use for reference. The 18-key layout is usually found on Mac keyboards.
  1438. ///
  1439. /// In particular, the plus key on the numpad is usually an elongated key that covers
  1440. /// the space of two keys. These 17-key numpads do not usually have a <see cref="numpadEqualsKey"/>
  1441. /// and the key above the plus key will usually be the numpad minus key.
  1442. ///
  1443. /// However, both on a 17-key and 18-key numpad, the plus key references the same physical key.
  1444. /// </remarks>
  1445. public KeyControl numpadPlusKey => this[Key.NumpadPlus];
  1446. /// <summary>
  1447. /// The period ('.') key on the numpad. The key in-between the <see cref="numpadEnterKey"/>
  1448. /// to the right and the <see cref="numpad0Key"/> to the left.
  1449. /// </summary>
  1450. /// <value>Control representing the numpad period key.</value>
  1451. /// <remarks>
  1452. /// This key is the same in 17-key and 18-key numpad layouts.
  1453. /// </remarks>
  1454. public KeyControl numpadPeriodKey => this[Key.NumpadPeriod];
  1455. /// <summary>
  1456. /// The equals ('=') key on the numpad. The key in-between <see cref="numLockKey"/> to the left
  1457. /// and <see cref="numpadDivideKey"/> to the right in the top row of the numpad.
  1458. /// </summary>
  1459. /// <value>Control representing the numpad equals key.</value>
  1460. /// <remarks>
  1461. /// PC keyboards usually have a 17-key numpad layout that differs from the 18-key layout
  1462. /// we use for reference. The 18-key layout is usually found on Mac keyboards.
  1463. ///
  1464. /// 17-key numpad layouts do not usually have an equals key. On these PC keyboards, the
  1465. /// equals key is usually the divide key.
  1466. /// </remarks>
  1467. public KeyControl numpadEqualsKey => this[Key.NumpadEquals];
  1468. /// <summary>
  1469. /// The 0 key on the numpad. The key in the bottom left corner of the numpad. Usually
  1470. /// and elongated key.
  1471. /// </summary>
  1472. /// <value>Control representing the numpad 0 key.</value>
  1473. public KeyControl numpad0Key => this[Key.Numpad0];
  1474. /// <summary>
  1475. /// The 1 key on the numpad. The key on the left side of the numpad with <see cref="numpad0Key"/>
  1476. /// below it and <see cref="numpad4Key"/> above it.
  1477. /// </summary>
  1478. /// <value>Control representing the numpad 1 key.</value>
  1479. public KeyControl numpad1Key => this[Key.Numpad1];
  1480. /// <summary>
  1481. /// The 2 key on the numpad. The key with the <see cref="numpad1Key"/> to its left and
  1482. /// the <see cref="numpad3Key"/> to its right.
  1483. /// </summary>
  1484. /// <value>Control representing the numpad 2 key.</value>
  1485. public KeyControl numpad2Key => this[Key.Numpad2];
  1486. /// <summary>
  1487. /// The 3 key on the numpad. The key with the <see cref="numpad2Key"/> to its left and
  1488. /// the <see cref="numpadEnterKey"/> to its right.
  1489. /// </summary>
  1490. /// <value>Control representing the numpad 3 key.</value>
  1491. public KeyControl numpad3Key => this[Key.Numpad3];
  1492. /// <summary>
  1493. /// The 4 key on the numpad. The key on the left side of the numpad with the <see cref="numpad1Key"/>
  1494. /// below it and the <see cref="numpad7Key"/> above it.
  1495. /// </summary>
  1496. /// <value>Control representing the numpad 4 key.</value>
  1497. public KeyControl numpad4Key => this[Key.Numpad4];
  1498. /// <summary>
  1499. /// The 5 key on the numpad. The key in-between the <see cref="numpad4Key"/> to the left and the
  1500. /// <see cref="numpad6Key"/> to the right.
  1501. /// </summary>
  1502. /// <value>Control representing the numpad 5 key.</value>
  1503. public KeyControl numpad5Key => this[Key.Numpad5];
  1504. /// <summary>
  1505. /// The 6 key on the numpad. The key in-between the <see cref="numpad5Key"/> to the let and
  1506. /// the <see cref="numpadPlusKey"/> to the right.
  1507. /// </summary>
  1508. /// <value>Control representing the numpad 6 key.</value>
  1509. public KeyControl numpad6Key => this[Key.Numpad6];
  1510. /// <summary>
  1511. /// The 7 key on the numpad. The key on the left side of the numpad with <see cref="numpad4Key"/>
  1512. /// below it and <see cref="numLockKey"/> above it.
  1513. /// </summary>
  1514. /// <value>Control representing the numpad 7 key.</value>
  1515. public KeyControl numpad7Key => this[Key.Numpad7];
  1516. /// <summary>
  1517. /// The 8 key on the numpad. The key in-between the <see cref="numpad7Key"/> to the left and the
  1518. /// <see cref="numpad9Key"/> to the right.
  1519. /// </summary>
  1520. /// <value>Control representing the numpad 8 key.</value>
  1521. public KeyControl numpad8Key => this[Key.Numpad8];
  1522. /// <summary>
  1523. /// The 9 key on the numpad. The key in-between the <see cref="numpad8Key"/> to the left and
  1524. /// the <see cref="numpadMinusKey"/> to the right (or, on 17-key PC keyboard numpads, the elongated
  1525. /// plus key).
  1526. /// </summary>
  1527. /// <value>Control representing the numpad 9 key.</value>
  1528. public KeyControl numpad9Key => this[Key.Numpad9];
  1529. /// <summary>
  1530. /// The F1 key. The key in-between <see cref="escapeKey"/> to the left and <see cref="f1Key"/>
  1531. /// to the right in the topmost row of keys.
  1532. /// </summary>
  1533. /// <value>Control representing the F1 key.</value>
  1534. public KeyControl f1Key => this[Key.F1];
  1535. /// <summary>
  1536. /// The F2 key. The key in-between <see cref="f1Key"/> to the left and <see cref="f3Key"/>
  1537. /// to the right in the topmost row of keys.
  1538. /// </summary>
  1539. /// <value>Control representing the F2 key.</value>
  1540. public KeyControl f2Key => this[Key.F2];
  1541. /// <summary>
  1542. /// The F3 key. The key in-between <see cref="f2Key"/> to the left and <see cref="f4Key"/>
  1543. /// to the right in the topmost row of keys.
  1544. /// </summary>
  1545. /// <value>Control representing the F3 key.</value>
  1546. public KeyControl f3Key => this[Key.F3];
  1547. /// <summary>
  1548. /// The F4 key. The key in-between <see cref="f3Key"/> to the left and <see cref="f5Key"/>
  1549. /// to the right in the topmost row of keys.
  1550. /// </summary>
  1551. /// <value>Control representing the F4 key.</value>
  1552. public KeyControl f4Key => this[Key.F4];
  1553. /// <summary>
  1554. /// The F5 key. The key in-between <see cref="f4Key"/> to the left and <see cref="f6Key"/>
  1555. /// to the right in the topmost row of keys.
  1556. /// </summary>
  1557. /// <value>Control representing the F5 key.</value>
  1558. public KeyControl f5Key => this[Key.F5];
  1559. /// <summary>
  1560. /// The F6 key. The key in-between <see cref="f5Key"/> to the left and <see cref="f7Key"/>
  1561. /// to the right in the topmost row of keys.
  1562. /// </summary>
  1563. /// <value>Control representing the F6 key.</value>
  1564. public KeyControl f6Key => this[Key.F6];
  1565. /// <summary>
  1566. /// The F7 key. The key in-between <see cref="f6Key"/> to the left and <see cref="f8Key"/>
  1567. /// to the right in the topmost row of keys.
  1568. /// </summary>
  1569. /// <value>Control representing the F7 key.</value>
  1570. public KeyControl f7Key => this[Key.F7];
  1571. /// <summary>
  1572. /// The F8 key. The key in-between <see cref="f7Key"/> to the left and <see cref="f9Key"/>
  1573. /// to the right in the topmost row of keys.
  1574. /// </summary>
  1575. /// <value>Control representing the F8 key.</value>
  1576. public KeyControl f8Key => this[Key.F8];
  1577. /// <summary>
  1578. /// The F9 key. The key in-between <see cref="f8Key"/> to the left and <see cref="f10Key"/>
  1579. /// to the right in the topmost row of keys.
  1580. /// </summary>
  1581. /// <value>Control representing the F9 key.</value>
  1582. public KeyControl f9Key => this[Key.F9];
  1583. /// <summary>
  1584. /// The F10 key. The key in-between <see cref="f9Key"/> to the left and <see cref="f11Key"/>
  1585. /// to the right in the topmost row of keys.
  1586. /// </summary>
  1587. /// <value>Control representing the F10 key.</value>
  1588. public KeyControl f10Key => this[Key.F10];
  1589. /// <summary>
  1590. /// The F11 key. The key in-between <see cref="f10Key"/> to the left and <see cref="f12Key"/>
  1591. /// to the right in the topmost row of keys.
  1592. /// </summary>
  1593. /// <value>Control representing the F11 key.</value>
  1594. public KeyControl f11Key => this[Key.F11];
  1595. /// <summary>
  1596. /// The F12 key. The key in-between <see cref="f11Key"/> to the left and <see cref="printScreenKey"/>
  1597. /// to the right in the topmost row of keys.
  1598. /// </summary>
  1599. /// <value>Control representing the F12 key.</value>
  1600. public KeyControl f12Key => this[Key.F12];
  1601. /// <summary>
  1602. /// First additional key on the keyboard.
  1603. /// </summary>
  1604. /// <value>Control representing <see cref="Key.OEM1"/>.</value>
  1605. /// <remarks>
  1606. /// Keyboards may have additional keys that are not part of the standardized 104-key keyboard layout
  1607. /// (105 in the case of an 18-key numpad). For example, many non-English keyboard layouts have an additional
  1608. /// key in-between <see cref="leftShiftKey"/> and <see cref="zKey"/>.
  1609. ///
  1610. /// Additional keys may be surfaced by the platform as "OEM" keys. There is no guarantee about where the
  1611. /// keys are located and what symbols they produce. The OEM key controls are mainly there to surface the
  1612. /// inputs but not with the intention of being used in standard bindings.
  1613. /// </remarks>
  1614. public KeyControl oem1Key => this[Key.OEM1];
  1615. /// <summary>
  1616. /// Second additional key on the keyboard.
  1617. /// </summary>
  1618. /// <value>Control representing <see cref="Key.OEM2"/>.</value>
  1619. /// <remarks>
  1620. /// Keyboards may have additional keys that are not part of the standardized 104-key keyboard layout
  1621. /// (105 in the case of an 18-key numpad). For example, many non-English keyboard layouts have an additional
  1622. /// key in-between <see cref="leftShiftKey"/> and <see cref="zKey"/>.
  1623. ///
  1624. /// Additional keys may be surfaced by the platform as "OEM" keys. There is no guarantee about where the
  1625. /// keys are located and what symbols they produce. The OEM key controls are mainly there to surface the
  1626. /// inputs but not with the intention of being used in standard bindings.
  1627. /// </remarks>
  1628. public KeyControl oem2Key => this[Key.OEM2];
  1629. /// <summary>
  1630. /// Third additional key on the keyboard.
  1631. /// </summary>
  1632. /// <value>Control representing <see cref="Key.OEM3"/>.</value>
  1633. /// <remarks>
  1634. /// Keyboards may have additional keys that are not part of the standardized 104-key keyboard layout
  1635. /// (105 in the case of an 18-key numpad). For example, many non-English keyboard layouts have an additional
  1636. /// key in-between <see cref="leftShiftKey"/> and <see cref="zKey"/>.
  1637. ///
  1638. /// Additional keys may be surfaced by the platform as "OEM" keys. There is no guarantee about where the
  1639. /// keys are located and what symbols they produce. The OEM key controls are mainly there to surface the
  1640. /// inputs but not with the intention of being used in standard bindings.
  1641. /// </remarks>
  1642. public KeyControl oem3Key => this[Key.OEM3];
  1643. /// <summary>
  1644. /// Fourth additional key on the keyboard.
  1645. /// </summary>
  1646. /// <value>Control representing <see cref="Key.OEM4"/>.</value>
  1647. /// <remarks>
  1648. /// Keyboards may have additional keys that are not part of the standardized 104-key keyboard layout
  1649. /// (105 in the case of an 18-key numpad). For example, many non-English keyboard layouts have an additional
  1650. /// key in-between <see cref="leftShiftKey"/> and <see cref="zKey"/>.
  1651. ///
  1652. /// Additional keys may be surfaced by the platform as "OEM" keys. There is no guarantee about where the
  1653. /// keys are located and what symbols they produce. The OEM key controls are mainly there to surface the
  1654. /// inputs but not with the intention of being used in standard bindings.
  1655. /// </remarks>
  1656. public KeyControl oem4Key => this[Key.OEM4];
  1657. /// <summary>
  1658. /// Fifth additional key on the keyboard.
  1659. /// </summary>
  1660. /// <value>Control representing <see cref="Key.OEM5"/>.</value>
  1661. /// <remarks>
  1662. /// Keyboards may have additional keys that are not part of the standardized 104-key keyboard layout
  1663. /// (105 in the case of an 18-key numpad). For example, many non-English keyboard layouts have an additional
  1664. /// key in-between <see cref="leftShiftKey"/> and <see cref="zKey"/>.
  1665. ///
  1666. /// Additional keys may be surfaced by the platform as "OEM" keys. There is no guarantee about where the
  1667. /// keys are located and what symbols they produce. The OEM key controls are mainly there to surface the
  1668. /// inputs but not with the intention of being used in standard bindings.
  1669. /// </remarks>
  1670. public KeyControl oem5Key => this[Key.OEM5];
  1671. /// <summary>
  1672. /// An artificial combination of <see cref="leftShiftKey"/> and <see cref="rightShiftKey"/> into one control.
  1673. /// </summary>
  1674. /// <value>Control representing a combined left and right shift key.</value>
  1675. /// <remarks>
  1676. /// This is a <see cref="InputControl.synthetic"/> button which is considered pressed whenever the left and/or
  1677. /// right shift key is pressed.
  1678. /// </remarks>
  1679. public ButtonControl shiftKey { get; protected set; }
  1680. /// <summary>
  1681. /// An artificial combination of <see cref="leftCtrlKey"/> and <see cref="rightCtrlKey"/> into one control.
  1682. /// </summary>
  1683. /// <value>Control representing a combined left and right ctrl key.</value>
  1684. /// <remarks>
  1685. /// This is a <see cref="InputControl.synthetic"/> button which is considered pressed whenever the left and/or
  1686. /// right ctrl key is pressed.
  1687. /// </remarks>
  1688. public ButtonControl ctrlKey { get; protected set; }
  1689. /// <summary>
  1690. /// An artificial combination of <see cref="leftAltKey"/> and <see cref="rightAltKey"/> into one control.
  1691. /// </summary>
  1692. /// <value>Control representing a combined left and right alt key.</value>
  1693. /// <remarks>
  1694. /// This is a <see cref="InputControl.synthetic"/> button which is considered pressed whenever the left and/or
  1695. /// right alt key is pressed.
  1696. /// </remarks>
  1697. public ButtonControl altKey { get; protected set; }
  1698. /// <summary>
  1699. /// True when IME composition is enabled. Requires <see cref="Keyboard.SetIMEEnabled"/> to be called to enable IME, and the user to enable it at the OS level.
  1700. /// </summary>
  1701. /// <remarks>
  1702. ///
  1703. /// Some languages use complex input methods which involve opening windows to insert characters.
  1704. /// Typically, this is not desirable while playing a game, as games may just interpret key strokes as game input, not as text.
  1705. ///
  1706. /// See <see cref="Keyboard.SetIMEEnabled"/> for turning IME on/off
  1707. /// </remarks>
  1708. public ButtonControl imeSelected { get; protected set; }
  1709. /// <summary>
  1710. /// Look up a key control by its key code.
  1711. /// </summary>
  1712. /// <param name="key">Key code of key control to return.</param>
  1713. /// <exception cref="ArgumentOutOfRangeException">The given <paramref cref="key"/> is not valid.</exception>
  1714. /// <remarks>
  1715. /// This is equivalent to <c>allKeys[(int)key - 1]</c>.
  1716. /// </remarks>
  1717. public KeyControl this[Key key]
  1718. {
  1719. get
  1720. {
  1721. var index = (int)key - 1;
  1722. if (index < 0 || index >= m_Keys.Length)
  1723. throw new ArgumentOutOfRangeException(nameof(key));
  1724. return m_Keys[index];
  1725. }
  1726. }
  1727. /// <summary>
  1728. /// List of all key controls on the keyboard.
  1729. /// </summary>
  1730. public ReadOnlyArray<KeyControl> allKeys => new ReadOnlyArray<KeyControl>(m_Keys);
  1731. /// <summary>
  1732. /// The keyboard that was last used or added. Null if there is no keyboard.
  1733. /// </summary>
  1734. public static Keyboard current { get; private set; }
  1735. /// <summary>
  1736. /// Make the keyboard the current keyboard (i.e. <see cref="current"/>).
  1737. /// </summary>
  1738. /// <remarks>
  1739. /// A keyboard will automatically be made current when receiving input or when
  1740. /// added to the input system.
  1741. /// </remarks>
  1742. public override void MakeCurrent()
  1743. {
  1744. base.MakeCurrent();
  1745. current = this;
  1746. }
  1747. /// <summary>
  1748. /// Called when the keyboard is removed from the system.
  1749. /// </summary>
  1750. protected override void OnRemoved()
  1751. {
  1752. base.OnRemoved();
  1753. if (current == this)
  1754. current = null;
  1755. }
  1756. /// <summary>
  1757. /// Called after the keyboard has been constructed but before it is added to
  1758. /// the system.
  1759. /// </summary>
  1760. protected override void FinishSetup()
  1761. {
  1762. var keyStrings = new[]
  1763. {
  1764. "space",
  1765. "enter",
  1766. "tab",
  1767. "backquote",
  1768. "quote",
  1769. "semicolon",
  1770. "comma",
  1771. "period",
  1772. "slash",
  1773. "backslash",
  1774. "leftbracket",
  1775. "rightbracket",
  1776. "minus",
  1777. "equals",
  1778. "a",
  1779. "b",
  1780. "c",
  1781. "d",
  1782. "e",
  1783. "f",
  1784. "g",
  1785. "h",
  1786. "i",
  1787. "j",
  1788. "k",
  1789. "l",
  1790. "m",
  1791. "n",
  1792. "o",
  1793. "p",
  1794. "q",
  1795. "r",
  1796. "s",
  1797. "t",
  1798. "u",
  1799. "v",
  1800. "w",
  1801. "x",
  1802. "y",
  1803. "z",
  1804. "1",
  1805. "2",
  1806. "3",
  1807. "4",
  1808. "5",
  1809. "6",
  1810. "7",
  1811. "8",
  1812. "9",
  1813. "0",
  1814. "leftshift",
  1815. "rightshift",
  1816. "leftalt",
  1817. "rightalt",
  1818. "leftctrl",
  1819. "rightctrl",
  1820. "leftmeta",
  1821. "rightmeta",
  1822. "contextmenu",
  1823. "escape",
  1824. "leftarrow",
  1825. "rightarrow",
  1826. "uparrow",
  1827. "downarrow",
  1828. "backspace",
  1829. "pagedown",
  1830. "pageup",
  1831. "home",
  1832. "end",
  1833. "insert",
  1834. "delete",
  1835. "capslock",
  1836. "numlock",
  1837. "printscreen",
  1838. "scrolllock",
  1839. "pause",
  1840. "numpadenter",
  1841. "numpaddivide",
  1842. "numpadmultiply",
  1843. "numpadplus",
  1844. "numpadminus",
  1845. "numpadperiod",
  1846. "numpadequals",
  1847. "numpad0",
  1848. "numpad1",
  1849. "numpad2",
  1850. "numpad3",
  1851. "numpad4",
  1852. "numpad5",
  1853. "numpad6",
  1854. "numpad7",
  1855. "numpad8",
  1856. "numpad9",
  1857. "f1",
  1858. "f2",
  1859. "f3",
  1860. "f4",
  1861. "f5",
  1862. "f6",
  1863. "f7",
  1864. "f8",
  1865. "f9",
  1866. "f10",
  1867. "f11",
  1868. "f12",
  1869. "oem1",
  1870. "oem2",
  1871. "oem3",
  1872. "oem4",
  1873. "oem5",
  1874. };
  1875. m_Keys = new KeyControl[keyStrings.Length];
  1876. for (var i = 0; i < keyStrings.Length; ++i)
  1877. {
  1878. m_Keys[i] = GetChildControl<KeyControl>(keyStrings[i]);
  1879. ////REVIEW: Ideally, we'd have a way to do this through layouts; this way nested key controls could work, too,
  1880. //// and it just seems somewhat dirty to jam the data into the control here
  1881. m_Keys[i].keyCode = (Key)(i + 1);
  1882. }
  1883. Debug.Assert(keyStrings[(int)Key.OEM5 - 1] == "oem5",
  1884. "keyString array layout doe not match Key enum layout");
  1885. anyKey = GetChildControl<AnyKeyControl>("anyKey");
  1886. shiftKey = GetChildControl<ButtonControl>("shift");
  1887. ctrlKey = GetChildControl<ButtonControl>("ctrl");
  1888. altKey = GetChildControl<ButtonControl>("alt");
  1889. imeSelected = GetChildControl<ButtonControl>("IMESelected");
  1890. base.FinishSetup();
  1891. }
  1892. /// <inheritdoc/>
  1893. protected override void RefreshConfiguration()
  1894. {
  1895. keyboardLayout = null;
  1896. var command = QueryKeyboardLayoutCommand.Create();
  1897. if (ExecuteCommand(ref command) >= 0)
  1898. keyboardLayout = command.ReadLayoutName();
  1899. }
  1900. /// <summary>
  1901. /// Called when text input on the keyboard is received.
  1902. /// </summary>
  1903. /// <param name="character">Character that has been entered.</param>
  1904. /// <remarks>
  1905. /// The system will call this automatically whenever a <see cref="TextEvent"/> is
  1906. /// received that targets the keyboard device.
  1907. /// </remarks>
  1908. public void OnTextInput(char character)
  1909. {
  1910. for (var i = 0; i < m_TextInputListeners.length; ++i)
  1911. m_TextInputListeners[i](character);
  1912. }
  1913. /// <summary>
  1914. /// Return the key control that, according to the currently active keyboard layout (see <see cref="keyboardLayout"/>),
  1915. /// is associated with the given text.
  1916. /// </summary>
  1917. /// <param name="displayName">Display name reported for the key according to the currently active keyboard layout.</param>
  1918. /// <returns>The key control corresponding to the given text or <c>null</c> if no such key was found on the current
  1919. /// keyboard layout.</returns>
  1920. /// <remarks>
  1921. /// In most cases, this means that the key inputs the given text when pressed. However, this does not have to be the
  1922. /// case. Keys do not necessarily lead to character input.
  1923. ///
  1924. /// <example>
  1925. /// // Find key that prints 'q' character (if any).
  1926. /// Keyboard.current.FindKeyOnCurrentKeyboardLayout("q");
  1927. /// </example>
  1928. /// </remarks>
  1929. /// <seealso cref="keyboardLayout"/>
  1930. public KeyControl FindKeyOnCurrentKeyboardLayout(string displayName)
  1931. {
  1932. var keys = allKeys;
  1933. for (var i = 0; i < keys.Count; ++i)
  1934. if (string.Equals(keys[i].displayName, displayName, StringComparison.CurrentCultureIgnoreCase))
  1935. return keys[i];
  1936. return null;
  1937. }
  1938. public void OnIMECompositionChanged(IMECompositionString compositionString)
  1939. {
  1940. if (m_ImeCompositionListeners.length > 0)
  1941. {
  1942. for (var i = 0; i < m_ImeCompositionListeners.length; ++i)
  1943. m_ImeCompositionListeners[i](compositionString);
  1944. }
  1945. }
  1946. private InlinedArray<Action<char>> m_TextInputListeners;
  1947. private string m_KeyboardLayoutName;
  1948. private KeyControl[] m_Keys;
  1949. private InlinedArray<Action<IMECompositionString>> m_ImeCompositionListeners;
  1950. /// <summary>
  1951. /// Raw array of key controls on the keyboard.
  1952. /// </summary>
  1953. protected KeyControl[] keys
  1954. {
  1955. get => m_Keys;
  1956. set => m_Keys = value;
  1957. }
  1958. }
  1959. }