From 58a825dd91c2853aac12829a19f5ca77cfc299df Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Thu, 1 Dec 2022 17:20:10 +0100 Subject: [PATCH] Fix Release ghost pressing of key backspace, del, ... Add debug log for imgui update key data - aka key events --- src/slic3r/GUI/ImGuiWrapper.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 17709788d7..233e102a6c 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -257,20 +257,37 @@ bool ImGuiWrapper::update_key_data(wxKeyEvent &evt) return false; } - ImGuiIO& io = ImGui::GetIO(); + auto to_string = [](wxEventType type) -> std::string { + if (type == wxEVT_CHAR) return "Char"; + if (type == wxEVT_KEY_DOWN) return "KeyDown"; + if (type == wxEVT_KEY_UP) return "KeyUp"; + return "Other"; + }; - if (evt.GetEventType() == wxEVT_CHAR) { + wxEventType type = evt.GetEventType(); + ImGuiIO& io = ImGui::GetIO(); + BOOST_LOG_TRIVIAL(debug) << "ImGui - key event(" << to_string(type) << "):" + //<< " Unicode(" << evt.GetUnicodeKey() << ")" + << " KeyCode(" << evt.GetKeyCode() << ")"; + + if (type == wxEVT_CHAR) { // Char event - const auto key = evt.GetUnicodeKey(); + const auto key = evt.GetUnicodeKey(); + unsigned int key_u = static_cast(key); + // Release BackSpace, Delete, ... when miss wxEVT_KEY_UP event + if (key_u >= 0 && key_u < IM_ARRAYSIZE(io.KeysDown) && io.KeysDown[key_u]) { + io.KeysDown[key_u] = false; + } + if (key != 0) { io.AddInputCharacter(key); } - } else { + } else if (type == wxEVT_KEY_DOWN || type == wxEVT_KEY_UP) { // Key up/down event int key = evt.GetKeyCode(); wxCHECK_MSG(key >= 0 && key < IM_ARRAYSIZE(io.KeysDown), false, "Received invalid key code"); - io.KeysDown[key] = evt.GetEventType() == wxEVT_KEY_DOWN; + io.KeysDown[key] = (type == wxEVT_KEY_DOWN); io.KeyShift = evt.ShiftDown(); io.KeyCtrl = evt.ControlDown(); io.KeyAlt = evt.AltDown();