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