From 42461c467f67421abb153dbe761aaa1ca9c2fa20 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 26 Mar 2021 21:40:35 +0100 Subject: [PATCH] ux: Properly use current key layout for shortcuts --- source/views/view_command_palette.cpp | 2 +- source/views/view_hexeditor.cpp | 14 +++++++------- source/window.cpp | 5 +++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/source/views/view_command_palette.cpp b/source/views/view_command_palette.cpp index 66fe9c898..3651110ad 100644 --- a/source/views/view_command_palette.cpp +++ b/source/views/view_command_palette.cpp @@ -68,7 +68,7 @@ namespace hex { } bool ViewCommandPalette::handleShortcut(int key, int mods) { - if (key == GLFW_KEY_P && mods == (GLFW_MOD_SHIFT | GLFW_MOD_CONTROL)) { + if (key == 'P' && mods == (GLFW_MOD_SHIFT | GLFW_MOD_CONTROL)) { View::doLater([this] { ImGui::OpenPopup("hex.view.command_palette.name"_lang); this->m_commandPaletteOpen = true; diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index b8772298d..7176b3957 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -501,25 +501,25 @@ namespace hex { } bool ViewHexEditor::handleShortcut(int key, int mods) { - if (mods == GLFW_MOD_CONTROL && key == GLFW_KEY_S) { + if (mods == GLFW_MOD_CONTROL && key == 'S') { save(); return true; - } else if (mods == (GLFW_MOD_CONTROL | GLFW_MOD_SHIFT) && key == GLFW_KEY_S) { + } else if (mods == (GLFW_MOD_CONTROL | GLFW_MOD_SHIFT) && key == 'S') { saveAs(); return true; - } else if (mods == GLFW_MOD_CONTROL && key == GLFW_KEY_F) { + } else if (mods == GLFW_MOD_CONTROL && key == 'Z') { View::doLater([]{ ImGui::OpenPopup("hex.view.hexeditor.menu.file.search"_lang); }); return true; - } else if (mods == GLFW_MOD_CONTROL && key == GLFW_KEY_G) { + } else if (mods == GLFW_MOD_CONTROL && key == 'G') { View::doLater([]{ ImGui::OpenPopup("hex.view.hexeditor.menu.file.goto"_lang); }); return true; - } else if (mods == GLFW_MOD_CONTROL && key == GLFW_KEY_O) { + } else if (mods == GLFW_MOD_CONTROL && key == 'O') { View::doLater([]{ ImGui::OpenPopup("hex.view.hexeditor.open_file"_lang); }); return true; - } else if (mods == (GLFW_MOD_CONTROL | GLFW_MOD_ALT) && key == GLFW_KEY_C) { + } else if (mods == (GLFW_MOD_CONTROL | GLFW_MOD_ALT) && key == 'C') { this->copyBytes(); return true; - } else if (mods == (GLFW_MOD_CONTROL | GLFW_MOD_SHIFT) && key == GLFW_KEY_C) { + } else if (mods == (GLFW_MOD_CONTROL | GLFW_MOD_SHIFT) && key == 'C') { this->copyString(); return true; } diff --git a/source/window.cpp b/source/window.cpp index 7689dbdf2..c1972197e 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -612,6 +612,11 @@ namespace hex { }); glfwSetKeyCallback(this->m_window, [](GLFWwindow *window, int key, int scancode, int action, int mods) { + + auto keyName = glfwGetKeyName(key, scancode); + if (keyName != nullptr) + key = std::toupper(keyName[0]); + if (action == GLFW_PRESS) { Window::s_currShortcut = { key, mods }; auto &io = ImGui::GetIO();