@@ -303,22 +303,22 @@ public void Actions_WhenShortcutsEnabled_CanConsumeInput(bool legacyComposites)
303303 [Category("Actions Priority")]
304304 [TestCase("ctrl", "x", true)]
305305 [TestCase("ctrl", "x", false)]
306- public void Actions_PressingModifierShortcutWithSameBinding_TriggersHighestPriorityAction (string sharedModifier, string binding1, bool legacyComposites)
306+ public void Actions_Priority_PressingModifierShortcutWithSameBinding_TriggersHighestPriorityAction (string sharedModifier, string binding1, bool legacyComposites)
307307 {
308308 InputSystem.settings.shortcutKeysConsumeInput = true;
309309 var keyboard = InputSystem.AddDevice<Keyboard>();
310-
311310 var map = new InputActionMap("map");
311+
312+ var action1 = map.AddAction("action1");
313+ action1.AddBinding("<Keyboard>/" + binding1);
314+
312315 var action2 = map.AddAction("action2");
313316 action2.AddCompositeBinding((legacyComposites ? "ButtonWithOneModifier" : "OneModifier") + "(overrideModifiersNeedToBePressedFirst)")
314317 .With("Modifier", "<Keyboard>/" + sharedModifier)
315318 .With(legacyComposites ? "Button" : "Binding", "<Keyboard>/" + binding1);
316319
317- var action1 = map.AddAction("action1");
318- action1.AddBinding("<Keyboard>/" + binding1);
319-
320- action1.Priority = 10;
321- action2.Priority = 9;
320+ action1.Priority = 9;
321+ action2.Priority = 10;
322322
323323 map.Enable();
324324
@@ -330,14 +330,15 @@ public void Actions_PressingModifierShortcutWithSameBinding_TriggersHighestPrior
330330 InputSystem.Update();
331331
332332 // Action2 won't be performed due to the priority being below action2
333- Assert.That(action1.WasPerformedThisFrame(), Is.True );
334- Assert.That(action2.WasPerformedThisFrame(), Is.False );
333+ Assert.That(action1.WasPerformedThisFrame(), Is.False );
334+ Assert.That(action2.WasPerformedThisFrame(), Is.True );
335335 }
336336
337337 [Test]
338338 [Category("Actions Priority")]
339339 [TestCase("ctrl", "shift", "x", false)]
340- public void Actions_PressingTwoShortcutAtSameTime_TriggersOneShortcutDueToPriority(string sharedModifier, string sharedModifier2, string binding1, bool legacyComposites)
340+ [TestCase("ctrl", "shift", "x", true)]
341+ public void Actions_Priority_PressingTwoShortcutAtSameTime_TriggersOneShortcutDueToPriority(string sharedModifier, string sharedModifier2, string binding1, bool legacyComposites)
341342 {
342343 InputSystem.settings.shortcutKeysConsumeInput = true;
343344 var keyboard = InputSystem.AddDevice<Keyboard>();
@@ -374,6 +375,60 @@ public void Actions_PressingTwoShortcutAtSameTime_TriggersOneShortcutDueToPriori
374375 Assert.That(action2.WasPerformedThisFrame(), Is.True);
375376 }
376377
378+ [UnityTest]
379+ [Category("Actions Priority")]
380+ public IEnumerator Actions_Priority_PressingTwoShortcutAtSameTime_TriggersBothDueToNoConflictingBinding()
381+ {
382+ string sharedModifier = "ctrl";
383+ string binding1 = "x";
384+ string binding2 = "c";
385+
386+ InputSystem.settings.shortcutKeysConsumeInput = true;
387+ var keyboard = InputSystem.AddDevice<Keyboard>();
388+
389+ var map = new InputActionMap("map");
390+ var action1 = map.AddAction("action1");
391+ action1.AddCompositeBinding(("OneModifier") + "(overrideModifiersNeedToBePressedFirst)")
392+ .With("Modifier", "<Keyboard>/" + sharedModifier)
393+ .With("Binding", "<Keyboard>/" + binding1);
394+
395+ var action2 = map.AddAction("action2");
396+ action2.AddCompositeBinding(("OneModifier") + "(overrideModifiersNeedToBePressedFirst)")
397+ .With("Modifier", "<Keyboard>/" + sharedModifier)
398+ .With("Binding", "<Keyboard>/" + binding2);
399+
400+ action1.Priority = 0;
401+ action2.Priority = 1;
402+
403+ map.Enable();
404+
405+ var action1WasPerformed = false;
406+ action1.performed += _ => action1WasPerformed = true;
407+
408+ Assert.That(action1.WasPerformedThisFrame(), Is.False);
409+ Assert.That(action2.WasPerformedThisFrame(), Is.False);
410+
411+ Press((ButtonControl)keyboard[sharedModifier], queueEventOnly: true);
412+ Press((ButtonControl)keyboard[binding1], queueEventOnly: true);
413+ Press((ButtonControl)keyboard[binding2], queueEventOnly: true);
414+ InputSystem.Update();
415+
416+ // Action1 won't be performed due to the priority being below action2
417+ Assert.That(action1WasPerformed, Is.True);
418+ Assert.That(action2.WasPerformedThisFrame(), Is.True);
419+
420+ yield return null;
421+
422+ // Repeat as we shouldn't see the shortcut being performed again on repeat.
423+ Press((ButtonControl)keyboard[binding1], queueEventOnly: true);
424+ Press((ButtonControl)keyboard[binding2], queueEventOnly: true);
425+
426+ InputSystem.Update();
427+
428+ Assert.That(action2.WasPerformedThisFrame(), Is.False);
429+ Assert.That(action2.WasPerformedThisFrame(), Is.False);
430+ }
431+
377432 [Test]
378433 [Category("Actions")]
379434 public void Actions_ShortcutSupportDisabledByDefault()
0 commit comments