Skip to content

Commit c89f80d

Browse files
authored
NEW: Add new public setting to enable shortcut key consumption (ISXB-254) (#1602)
* CHANGE: shortcut support disabled by default * add test and fix shortcut specific tests * review changes. fix changelog entry * review comments: add shortcut feature toggle to the Project Settings * review comments: modify changelog * formatting * review comments: improve descriptions * remove deprecation warning * more specific property name * NEW: Add new public setting to enable shortcut key consumption * review comments: improve comments * add changelog entry
1 parent 6de2d2e commit c89f80d

File tree

10 files changed

+40
-31
lines changed

10 files changed

+40
-31
lines changed

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void Actions_WhenShortcutsDisabled_AllConflictingActionsTrigger()
7272
[TestCase(false)]
7373
public void Actions_WhenShortcutsEnabled_CanConsumeInput(bool legacyComposites)
7474
{
75-
InputSystem.settings.SetInternalFeatureFlag(InputFeatureNames.kDisableShortcutSupport, false);
75+
InputSystem.settings.shortcutKeysConsumeInput = true;
7676

7777
var keyboard = InputSystem.AddDevice<Keyboard>();
7878

@@ -164,7 +164,7 @@ public void Actions_WhenShortcutsEnabled_CanConsumeInput(bool legacyComposites)
164164
[Category("Actions")]
165165
public void Actions_ShortcutSupportDisabledByDefault()
166166
{
167-
Assert.That(InputSystem.settings.IsFeatureEnabled(InputFeatureNames.kDisableShortcutSupport), Is.True);
167+
Assert.That(InputSystem.settings.shortcutKeysConsumeInput, Is.False);
168168

169169
var keyboard = InputSystem.AddDevice<Keyboard>();
170170

@@ -252,7 +252,7 @@ public void Actions_CanBindMultipleShortcutSequencesBasedOnSameModifiers()
252252
[TestCase("leftShift", "leftAlt", "space", false)]
253253
public void Actions_WhenShortcutsEnabled_PressingShortcutSequenceInWrongOrder_DoesNotTriggerShortcut(string modifier1, string modifier2, string binding, bool legacyComposites)
254254
{
255-
InputSystem.settings.SetInternalFeatureFlag(InputFeatureNames.kDisableShortcutSupport, false);
255+
InputSystem.settings.shortcutKeysConsumeInput = true;
256256

257257
var keyboard = InputSystem.AddDevice<Keyboard>();
258258

@@ -330,7 +330,7 @@ public void Actions_PressingShortcutSequenceInWrongOrder_DoesNotTriggerShortcut_
330330
[Category("Actions")]
331331
public void Actions_WhenShortcutsAreEnabled_CanHaveShortcutsWithButtonsUsingInitialStateChecks()
332332
{
333-
InputSystem.settings.SetInternalFeatureFlag(InputFeatureNames.kDisableShortcutSupport, false);
333+
InputSystem.settings.shortcutKeysConsumeInput = true;
334334

335335
var keyboard = InputSystem.AddDevice<Keyboard>();
336336

@@ -8229,7 +8229,7 @@ public void Actions_CompositesReportControlThatTriggeredTheCompositeInCallback()
82298229
public void Actions_CompositesInDifferentMapsTiedToSameControlsWork()
82308230
{
82318231
// This test relies on the same single input getting picked up by two different composites.
8232-
InputSystem.settings.SetInternalFeatureFlag(InputFeatureNames.kDisableShortcutSupport, true);
8232+
InputSystem.settings.shortcutKeysConsumeInput = false;
82338233

82348234
var keyboard = InputSystem.AddDevice<Keyboard>();
82358235
var gamepad = InputSystem.AddDevice<Gamepad>();
@@ -10204,7 +10204,7 @@ public void Actions_WithMultipleCompositeBindings_WithoutEvaluateMagnitude_Works
1020410204
[TestCase(false)]
1020510205
public void Actions_ImprovedShortcutSupport_ConsumesWASD(bool shortcutsEnabled)
1020610206
{
10207-
InputSystem.settings.SetInternalFeatureFlag(InputFeatureNames.kDisableShortcutSupport, !shortcutsEnabled);
10207+
InputSystem.settings.shortcutKeysConsumeInput = shortcutsEnabled;
1020810208

1020910209
var keyboard = InputSystem.AddDevice<Keyboard>();
1021010210

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ however, it has to be formatted properly to pass verification tests.
1212

1313
### Added
1414
- Added support for reading Tracking State in [TrackedPoseDriver](xref:UnityEngine.InputSystem.XR.TrackedPoseDriver) to constrain whether the input pose is applied to the Transform. This should be used when the device supports valid flags for the position and rotation values, which is the case for XR poses.
15+
- Added `InputSettings.shortcutKeysConsumeInput`. This allows programmatic access to opt-in to the enhanced shortcut key behaviour ([case ISXB-254](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-254))).
1516

1617
### Fixed
1718
- Fixed composite bindings incorrectly getting a control scheme assigned when pasting into input asset editor with a control scheme selected.

Packages/com.unity.inputsystem/InputSystem/Actions/Composites/ButtonWithOneModifier.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ public override float EvaluateMagnitude(ref InputBindingCompositeContext context
131131
protected override void FinishSetup(ref InputBindingCompositeContext context)
132132
{
133133
if (!overrideModifiersNeedToBePressedFirst)
134-
overrideModifiersNeedToBePressedFirst =
135-
InputSystem.settings.IsFeatureEnabled(InputFeatureNames.kDisableShortcutSupport);
134+
overrideModifiersNeedToBePressedFirst = !InputSystem.settings.shortcutKeysConsumeInput;
136135
}
137136
}
138137
}

Packages/com.unity.inputsystem/InputSystem/Actions/Composites/ButtonWithTwoModifiers.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ public override float EvaluateMagnitude(ref InputBindingCompositeContext context
147147
protected override void FinishSetup(ref InputBindingCompositeContext context)
148148
{
149149
if (!overrideModifiersNeedToBePressedFirst)
150-
overrideModifiersNeedToBePressedFirst =
151-
InputSystem.settings.IsFeatureEnabled(InputFeatureNames.kDisableShortcutSupport);
150+
overrideModifiersNeedToBePressedFirst = !InputSystem.settings.shortcutKeysConsumeInput;
152151
}
153152
}
154153
}

Packages/com.unity.inputsystem/InputSystem/Actions/Composites/OneModifierComposite.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ protected override void FinishSetup(ref InputBindingCompositeContext context)
145145
DetermineValueTypeAndSize(ref context, binding, out m_ValueType, out m_ValueSizeInBytes, out m_BindingIsButton);
146146

147147
if (!overrideModifiersNeedToBePressedFirst)
148-
overrideModifiersNeedToBePressedFirst =
149-
InputSystem.settings.IsFeatureEnabled(InputFeatureNames.kDisableShortcutSupport);
148+
overrideModifiersNeedToBePressedFirst = !InputSystem.settings.shortcutKeysConsumeInput;
150149
}
151150

152151
public override object ReadValueAsObject(ref InputBindingCompositeContext context)

Packages/com.unity.inputsystem/InputSystem/Actions/Composites/TwoModifiersComposite.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ protected override void FinishSetup(ref InputBindingCompositeContext context)
158158
OneModifierComposite.DetermineValueTypeAndSize(ref context, binding, out m_ValueType, out m_ValueSizeInBytes, out m_BindingIsButton);
159159

160160
if (!overrideModifiersNeedToBePressedFirst)
161-
overrideModifiersNeedToBePressedFirst =
162-
InputSystem.settings.IsFeatureEnabled(InputFeatureNames.kDisableShortcutSupport);
161+
overrideModifiersNeedToBePressedFirst = !InputSystem.settings.shortcutKeysConsumeInput;
163162
}
164163

165164
public override object ReadValueAsObject(ref InputBindingCompositeContext context)

Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private void ComputeControlGroupingIfNecessary()
140140

141141
// If shortcut support is disabled, we simply put put all bindings at complexity=1 and
142142
// in their own group.
143-
var disableControlGrouping = InputSystem.settings.IsFeatureEnabled(InputFeatureNames.kDisableShortcutSupport);
143+
var disableControlGrouping = !InputSystem.settings.shortcutKeysConsumeInput;
144144

145145
var currentGroup = 1u;
146146
for (var i = 0; i < totalControlCount; ++i)

Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ public override void OnGUI(string searchContext)
152152
if (m_ShortcutKeysConsumeInputs.boolValue)
153153
EditorGUILayout.HelpBox("Please note that enabling Improved Shortcut Support will cause actions with composite bindings to consume input and block any other actions which are enabled and sharing the same controls. "
154154
+ "Input consumption is performed in priority order, with the action containing the greatest number of bindings checked first. "
155-
+ "Therefore actions requiring less keypresses will not be triggered if an action using more keypresses is triggered and has overlapping controls. "
155+
+ "Therefore actions requiring fewer keypresses will not be triggered if an action using more keypresses is triggered and has overlapping controls. "
156156
+ "This works for shortcut keys, however in other cases this might not give the desired result, especially where there are actions with the exact same number of composite controls, in which case it is non-deterministic which action will be triggered. "
157157
+ "These conflicts may occur even between actions which belong to different Action Maps e.g. if using an UIInputModule with the Arrow Keys bound to the Navigate Action in the UI Action Map, this would interfere with other Action Maps using those keys. "
158+
+ "However conflicts would not occur between actions which belong to different Action Assets. "
158159
+ "Since event consumption only occurs for enabled actions, you can resolve unexpected issues by ensuring that only those Actions or Action Maps that are relevant to your game's current context are enabled. Enabling or disabling actions as your game or application moves between different contexts. "
159160
, MessageType.None);
160161

Packages/com.unity.inputsystem/InputSystem/InputFeatureNames.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ internal static class InputFeatureNames
44
{
55
public const string kRunPlayerUpdatesInEditMode = "RUN_PLAYER_UPDATES_IN_EDIT_MODE";
66
public const string kDisableUnityRemoteSupport = "DISABLE_UNITY_REMOTE_SUPPORT";
7-
public const string kDisableShortcutSupport = "DISABLE_SHORTCUT_SUPPORT"; ////TODO: In v2, kill this.
87
public const string kUseWindowsGamingInputBackend = "USE_WINDOWS_GAMING_INPUT_BACKEND";
98
}
109
}

Packages/com.unity.inputsystem/InputSystem/InputSettings.cs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,32 @@ public bool disableRedundantEventsMerging
660660
}
661661
}
662662

663+
/// <summary>
664+
/// Improves shortcut key support by making composite controls consume control input
665+
/// </summary>
666+
/// <remarks>
667+
/// Actions are exclusively triggered and will consume/block other actions sharing the same input.
668+
/// E.g. when pressing the 'Shift+B' keys, the associated action would trigger but any action bound to just the 'B' key would be prevented from triggering at the same time.
669+
/// Please note that enabling this will cause actions with composite bindings to consume input and block any other actions which are enabled and sharing the same controls.
670+
/// Input consumption is performed in priority order, with the action containing the greatest number of bindings checked first.
671+
/// Therefore actions requiring fewer keypresses will not be triggered if an action using more keypresses is triggered and has overlapping controls.
672+
/// This works for shortcut keys, however in other cases this might not give the desired result, especially where there are actions with the exact same number of composite controls, in which case it is non-deterministic which action will be triggered.
673+
/// These conflicts may occur even between actions which belong to different Action Maps e.g. if using an UIInputModule with the Arrow Keys bound to the Navigate Action in the UI Action Map, this would interfere with other Action Maps using those keys.
674+
/// However conflicts would not occur between actions which belong to different Action Assets.
675+
/// </remarks>
676+
public bool shortcutKeysConsumeInput
677+
{
678+
get => m_ShortcutKeysConsumeInputs;
679+
set
680+
{
681+
if (m_ShortcutKeysConsumeInputs == value)
682+
return;
683+
684+
m_ShortcutKeysConsumeInputs = value;
685+
OnChange();
686+
}
687+
}
688+
663689
/// <summary>
664690
/// Enable or disable an internal feature by its name.
665691
/// </summary>
@@ -675,16 +701,6 @@ public void SetInternalFeatureFlag(string featureName, bool enabled)
675701
if (string.IsNullOrEmpty(featureName))
676702
throw new ArgumentNullException(nameof(featureName));
677703

678-
// REMOVE: this is a temporary crutch to disable shortcut support by default but while also preserving the
679-
// existing flag name, as users are aware of that now.
680-
if (featureName == InputFeatureNames.kDisableShortcutSupport)
681-
{
682-
if (m_ShortcutKeysConsumeInputs == !enabled) return;
683-
m_ShortcutKeysConsumeInputs = !enabled;
684-
OnChange();
685-
return;
686-
}
687-
688704
if (m_FeatureFlags == null)
689705
m_FeatureFlags = new HashSet<string>();
690706

@@ -728,10 +744,6 @@ public void SetInternalFeatureFlag(string featureName, bool enabled)
728744

729745
internal bool IsFeatureEnabled(string featureName)
730746
{
731-
// REMOVE: this is a temporary crutch to disable shortcut support by default but while also preserving the
732-
// existing flag name, as some users are aware of that now.
733-
if (featureName == InputFeatureNames.kDisableShortcutSupport) return !m_ShortcutKeysConsumeInputs;
734-
735747
return m_FeatureFlags != null && m_FeatureFlags.Contains(featureName.ToUpperInvariant());
736748
}
737749

0 commit comments

Comments
 (0)