From f287caa6c4a67f3f1fd3b34798e02939ef749360 Mon Sep 17 00:00:00 2001 From: Mino Date: Fri, 3 Mar 2023 12:39:40 +0900 Subject: [PATCH] Raise ImGui key events on KEYDOWN and block in-game text input on WantCaptureKeyboard --- .../ImGui_Impl/Input/ImGui_Input_Impl_Direct.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ImGuiScene/ImGui_Impl/Input/ImGui_Input_Impl_Direct.cs b/ImGuiScene/ImGui_Impl/Input/ImGui_Input_Impl_Direct.cs index bd70460..d0b8876 100644 --- a/ImGuiScene/ImGui_Impl/Input/ImGui_Input_Impl_Direct.cs +++ b/ImGuiScene/ImGui_Impl/Input/ImGui_Input_Impl_Direct.cs @@ -353,8 +353,13 @@ private bool UpdateMouseCursor() // Submit key event var key = VirtualKeyToImGuiKey((int)vk); var scancode = ((int)lParam & 0xff0000) >> 16; + AddKeyEvent(key, isKeyDown, vk, scancode); if (key != ImGuiKey.None && io.WantTextInput) { - AddKeyEvent(key, isKeyDown, vk, scancode); + return IntPtr.Zero; + } + + if (io.WantCaptureKeyboard) + { return IntPtr.Zero; } @@ -383,6 +388,10 @@ private bool UpdateMouseCursor() io.AddInputCharacter((uint)wParam); return IntPtr.Zero; } + if (io.WantCaptureKeyboard) + { + return IntPtr.Zero; + } break; // this never seemed to work reasonably, but I'll leave it for now case User32.WindowMessage.WM_SETCURSOR: @@ -463,9 +472,7 @@ private void ProcessKeyEventsWorkarounds() // Skip raising modifier keys if the game is focused. // This allows us to raise the keys when one is held and the window becomes unfocused, // but if we do not skip them, they will only be held down every 4th frame or so. - if (User32.GetForegroundWindow() == this._hWnd && - (IsGamepadKey((ImGuiKey) i) || - IsModKey((ImGuiKey) i))) + if (User32.GetForegroundWindow() == this._hWnd) continue; io.AddKeyEvent((ImGuiKey) i, false); }