From 55fdcbb3d17404136e874247e12e6f75e6e5d0c2 Mon Sep 17 00:00:00 2001
From: Morilli <35152647+Morilli@users.noreply.github.com>
Date: Sun, 18 Dec 2022 06:00:36 +0100
Subject: [PATCH] Don't set modifiers for key release events

this fixes a bug in 1df6ce4e38946564765dab9227ed093b5f33812f, where an incorrect modifier state could be set, causing the release event to not actually release the key. I also don't see a reason to not just not set modifiers.

For example: "Hold Tab", "Hold Shift", "Release Tab" would send a "Release:Shift+Tab" event which failed to release Tab, even though that key was initially pressed without Shift.

So, instead of trying to match the right modifiers and keys just send the released key without modifier state and let the Receive() function do the work.
---
 .../input/InputCoalescerControllers.cs                    | 8 --------
 src/BizHawk.Client.EmuHawk/Input/Input.cs                 | 4 +++-
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/src/BizHawk.Client.Common/input/InputCoalescerControllers.cs b/src/BizHawk.Client.Common/input/InputCoalescerControllers.cs
index 905ff583a6..9537d0f011 100644
--- a/src/BizHawk.Client.Common/input/InputCoalescerControllers.cs
+++ b/src/BizHawk.Client.Common/input/InputCoalescerControllers.cs
@@ -1,7 +1,6 @@
 #nullable enable
 
 using System.Linq;
-using BizHawk.Common.StringExtensions;
 using BizHawk.Emulation.Common;
 
 namespace BizHawk.Client.Common
@@ -32,13 +31,6 @@ namespace BizHawk.Client.Common
 	{
 		protected override void ProcessSubsets(string button, bool state)
 		{
-			// we don't want a release of e.g. "Ctrl+E" to release Ctrl as well
-			if (!state)
-			{
-				Buttons[button.SubstringAfterLast('+')] = state;
-				return;
-			}
-
 			// For controller input, we want Shift+X to register as both Shift and X (for Keyboard controllers)
 			foreach (var s in button.Split('+')) Buttons[s] = state;
 		}
diff --git a/src/BizHawk.Client.EmuHawk/Input/Input.cs b/src/BizHawk.Client.EmuHawk/Input/Input.cs
index 4c9367a8be..51092cc766 100644
--- a/src/BizHawk.Client.EmuHawk/Input/Input.cs
+++ b/src/BizHawk.Client.EmuHawk/Input/Input.cs
@@ -117,7 +117,9 @@ namespace BizHawk.Client.EmuHawk
 
 			// don't generate events for things like Ctrl+LeftControl
 			var mods = _modifiers;
-			if (currentModifier is not 0U)
+			if (!newState)
+				mods = 0; // don't set mods for release events, handle releasing all corresponding buttons later in InputCoalescer.Receive()
+			else if (currentModifier is not 0U)
 				mods &= ~currentModifier;
 
 			var ie = new InputEvent