From 37f9f5619ca4e9d668f7cf40115e9d266c20991f Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 18 Nov 2023 15:18:33 +0100 Subject: [PATCH] impr: Respect keyboard layouts for shortcuts again --- main/gui/source/window/window.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index c7e0fcf98..a98f3d330 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -1045,7 +1045,7 @@ namespace hex { #if !defined(OS_WEB) // Register key press callback - glfwSetKeyCallback(this->m_window, [](GLFWwindow *window, int key, int, int action, int mods) { + glfwSetKeyCallback(this->m_window, [](GLFWwindow *window, int key, int scanCode, int action, int mods) { hex::unused(mods); auto win = static_cast(glfwGetWindowUserPointer(window)); @@ -1056,6 +1056,18 @@ namespace hex { win->m_buttonDown = true; } + // Handle A-Z keys using their ASCII value instead of the keycode + if (key >= GLFW_KEY_A && key <= GLFW_KEY_Z) { + std::string_view name = glfwGetKeyName(key, scanCode); + + // If the key name is only one character long, use the ASCII value instead + // Otherwise the keyboard was set to a non-English layout and the key name + // is not the same as the ASCII value + if (name.length() == 1) { + key = std::toupper(name[0]); + } + } + if (key == GLFW_KEY_UNKNOWN) return; if (action == GLFW_PRESS || action == GLFW_REPEAT) {