Skip to content

Commit 37ee762

Browse files
DOCF-3045 Clarified information about key layout, text input and key controls (#1695)
* DOCF-3045 Clarified information about key layout, text input and key controls * DOCF-3045 Fixed broken links * Fixed formatting (trailing whitespace) --------- Co-authored-by: Lyndon Homewood <33493311+lyndon-unity@users.noreply.github.com>
1 parent 8786290 commit 37ee762

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

Packages/com.unity.inputsystem/InputSystem/Controls/KeyControl.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,27 @@ namespace UnityEngine.InputSystem.Controls
1212
/// have symbols associated with them which may change depending on keyboard layout as well as in combination
1313
/// with other keys.
1414
///
15-
/// Note that there is no text input associated with individual keys as text composition is highly
16-
/// layout specific and does not need to be key-by-key. For general text input, see <see cref="Keyboard.onTextInput"/>.
17-
/// To find the text displayed on a key, use <see cref="InputControl.displayName"/>.
15+
/// Note:
16+
/// Unity input system key codes and input manager key codes are designed with game controls in mind.
17+
///
18+
/// This means the way they are assigned is intended to preserve the location of keys on keyboards,
19+
/// so that pressing a key in the same location on different keyboards should result in the same action
20+
/// regardless of what is printed on a key or what current system language is set.
21+
///
22+
/// This means, for example, that <see cref="Key.A"/> is always the key to the right of <see cref="Key.CapsLock"/>,
23+
/// regardless of which key (if any) produces the "a" character on the current keyboard layout.
24+
///
25+
/// Unity relies on physical hardware in the keyboards to report same USB HID "usage" for the keys in
26+
/// the same location.This puts a practical limit on what can be achieved, because different keyboards
27+
/// might report different data, and this is outside of Unity's control.
28+
///
29+
/// For this reason, you should not use key codes to read text input.
30+
/// Instead, you should use the <see cref="Keyboard.onTextInput"/> callback.
31+
/// The `onTextInput` callback provides you with the actual text characters which correspond
32+
/// to the symbols printed on a keyboard, based on the end user's current system language layout.
33+
///
34+
/// To find the text character (if any) generated by a key according to the currently active keyboard
35+
/// layout, use the <see cref="InputControl.displayName"/> property of <see cref="KeyControl"/>.
1836
/// </remarks>
1937
public class KeyControl : ButtonControl
2038
{
@@ -24,6 +42,7 @@ public class KeyControl : ButtonControl
2442
/// <remarks>
2543
/// This property must be initialized by <see cref="InputControl.FinishSetup"/> of
2644
/// the device owning the control.
45+
/// You should not use `keyCode` to read text input. For more information, <see cref="KeyControl"/>
2746
/// </remarks>
2847
public Key keyCode { get; set; }
2948

Packages/com.unity.inputsystem/InputSystem/Devices/Keyboard.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,27 @@ namespace UnityEngine.InputSystem
197197
/// Enumeration of key codes.
198198
/// </summary>
199199
/// <remarks>
200-
/// Named according to the US keyboard layout which is used as a reference layout. Note, however,
201-
/// that keys are identified by physical location, not by the characters they generate. This means,
202-
/// for example, that <see cref="A"/> is always the key to the right of <see cref="CapsLock"/>,
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"/>,
203210
/// regardless of which key (if any) produces the "a" character on the current keyboard layout.
204211
///
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+
///
205221
/// To find the text character (if any) generated by a key according to the currently active keyboard
206222
/// layout, use the <see cref="InputControl.displayName"/> property of <see cref="KeyControl"/>.
207223
///

0 commit comments

Comments
 (0)