Keyboard.cs 88 KB

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