diff --git a/src/Input/Keyboard.cs b/src/Input/Keyboard.cs index e440988..983cac3 100644 --- a/src/Input/Keyboard.cs +++ b/src/Input/Keyboard.cs @@ -98,20 +98,36 @@ internal void Update(ulong timestamp) { wasPressed = ButtonWasPressed(timestamp, events); isDown = events[^1].down; + + if (isDown) + { + // First, check if the input window has text input active. + var mostRecentWindowID = events[^1].windowID; + Window.IDToWindow.TryGetValue(mostRecentWindowID, out var activeWindow); + + if (activeWindow == null) + { + Logger.LogError($"Input window with ID {mostRecentWindowID} is somehow invalid."); + } + else if (activeWindow.TextInputActive) + { + // If so, handle special text input characters. + if (TextInputBindings.TryGetValue(button.ScanCode, out var textIndex)) + { + Inputs.OnTextInput(TextInputCharacters[textIndex]); + } + else if (IsDown(ScanCode.LeftControl) && button.ScanCode == ScanCode.V) + { + Inputs.OnTextInput(TextInputCharacters[6]); + } + } + } + events.Clear(); } button.Update(wasPressed, isDown); - if (TextInputBindings.TryGetValue(button.ScanCode, out var textIndex)) - { - Inputs.OnTextInput(TextInputCharacters[(textIndex)]); - } - else if (IsDown(ScanCode.LeftControl) && button.ScanCode == ScanCode.V) - { - Inputs.OnTextInput(TextInputCharacters[6]); - } - if (button.IsPressed) { AnyPressed = true;