FIX: keyup event maybe not processed

jira: STUDIO-10958

Change-Id: I6d56f92f7cb2823b0d0a036d1da515270ebdba59
This commit is contained in:
jun.zhang 2025-03-19 16:27:27 +08:00 committed by lane.wei
parent c90948dc73
commit bf5d7811a0
1 changed files with 33 additions and 0 deletions

View File

@ -510,6 +510,39 @@ void ImGuiWrapper::new_frame()
init_font(true); 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<std::pair<ImGuiKeyModFlags_, wxKeyCode>, 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<ImGuiKeyModFlags_, wxKeyCode>& 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<wxKeyCode>(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<wxKeyCode>(key);
if (io.KeysDown[key] && keycode != WXK_NONE && !wxGetKeyState(keycode))
io.KeysDown[key] = false;
}
// BBL: end copy & paste
ImGui::NewFrame(); ImGui::NewFrame();
m_new_frame_open = true; m_new_frame_open = true;
} }