From bc342a89d02c39a691d35a1f790f475971ab3bda Mon Sep 17 00:00:00 2001 From: matcool <26722564+matcool@users.noreply.github.com> Date: Thu, 7 Dec 2023 17:09:25 -0300 Subject: [PATCH] always send release inputs from dispatchKeyboardMSG to imgui --- src/hooks.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/hooks.cpp b/src/hooks.cpp index a0d9818..5f2a111 100644 --- a/src/hooks.cpp +++ b/src/hooks.cpp @@ -80,14 +80,21 @@ bool shouldBlockInput() { class $modify(CCKeyboardDispatcher) { bool dispatchKeyboardMSG(enumKeyCodes key, bool down) { - if (!ImGuiCocos::get().isInitialized() || (!ImGui::GetIO().WantCaptureKeyboard && !shouldBlockInput())) { + if (!ImGuiCocos::get().isInitialized()) return CCKeyboardDispatcher::dispatchKeyboardMSG(key, down); + + const bool shouldEatInput = ImGui::GetIO().WantCaptureKeyboard || shouldBlockInput(); + if (shouldEatInput || !down) { + const auto imKey = cocosToImGuiKey(key); + if (imKey != ImGuiKey_None) { + ImGui::GetIO().AddKeyEvent(imKey, down); + } } - const auto imKey = cocosToImGuiKey(key); - if (imKey != ImGuiKey_None) { - ImGui::GetIO().AddKeyEvent(imKey, down); + if (shouldEatInput) { + return false; + } else { + return CCKeyboardDispatcher::dispatchKeyboardMSG(key, down); } - return false; } };