From bf5d7811a0e3a0fd545047a11208f64bcff77980 Mon Sep 17 00:00:00 2001 From: "jun.zhang" Date: Wed, 19 Mar 2025 16:27:27 +0800 Subject: [PATCH] FIX: keyup event maybe not processed jira: STUDIO-10958 Change-Id: I6d56f92f7cb2823b0d0a036d1da515270ebdba59 --- src/slic3r/GUI/ImGuiWrapper.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index ab639d091..845080a96 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -510,6 +510,39 @@ void ImGuiWrapper::new_frame() init_font(true); } + ImGuiIO& io = ImGui::GetIO(); + + // BBL: copy & paste form prusa github repo (https://github.com/prusa3d/PrusaSlicer/blob/master/src/slic3r/GUI/ImGuiWrapper.cpp#L375C5-L402C6) + // synchronize key states + // when the application loses the focus it may happen that the key up event is not processed + + // synchronize modifier keys + constexpr std::array, 3> imgui_mod_keys{ + std::make_pair(ImGuiKeyModFlags_Ctrl, WXK_CONTROL), + std::make_pair(ImGuiKeyModFlags_Shift, WXK_SHIFT), + std::make_pair(ImGuiKeyModFlags_Alt, WXK_ALT) }; + for (const std::pair& key : imgui_mod_keys) { + if ((io.KeyMods & key.first) != 0 && !wxGetKeyState(key.second)) + io.KeyMods &= ~key.first; + } + + // Not sure if it is neccessary + // values from 33 to 126 are reserved for the standard ASCII characters + for (size_t i = 33; i <= 126; ++i) { + wxKeyCode keycode = static_cast(i); + if (io.KeysDown[i] && keycode != WXK_NONE && !wxGetKeyState(keycode)) + io.KeysDown[i] = false; + } + + // special keys: delete, backspace, ... + for (int key : io.KeyMap) { + wxKeyCode keycode = static_cast(key); + if (io.KeysDown[key] && keycode != WXK_NONE && !wxGetKeyState(keycode)) + io.KeysDown[key] = false; + } + + // BBL: end copy & paste + ImGui::NewFrame(); m_new_frame_open = true; }