From 6ead8d8b49fbd623de0a55eb27be091b4eb48ec2 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 25 Dec 2024 12:36:06 +0100 Subject: [PATCH] fix: Certain shortcuts not being captured by ImHex Web --- dist/web/source/wasm-config.js | 6 +++++- main/gui/source/window/window.cpp | 26 +++++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/dist/web/source/wasm-config.js b/dist/web/source/wasm-config.js index 13908aefc..3b63e4ad0 100644 --- a/dist/web/source/wasm-config.js +++ b/dist/web/source/wasm-config.js @@ -261,4 +261,8 @@ function js_resizeCanvas() { canvas.left = document.documentElement.clientLeft; canvas.width = Math.min(document.documentElement.clientWidth, window.innerWidth || 0); canvas.height = Math.min(document.documentElement.clientHeight, window.innerHeight || 0); -} \ No newline at end of file +} + +// Prevent default browser shortcuts from preventing ImHex ones to work +document.addEventListener('keydown', e => { e.preventDefault(); }) +document.addEventListener('keyup', e => { e.preventDefault(); }) \ No newline at end of file diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index b6f786380..c75ed8371 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -890,20 +890,24 @@ namespace hex { glfwSetKeyCallback(m_window, [](GLFWwindow *window, int key, int scanCode, int action, int mods) { std::ignore = mods; - // 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 !defined(OS_WEB) + // 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.empty()) { - const std::uint8_t byte = name[0]; - if (name.length() == 1 && byte <= 0x7F) { - key = std::toupper(byte); + // 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.empty()) { + const std::uint8_t byte = name[0]; + if (name.length() == 1 && byte <= 0x7F) { + key = std::toupper(byte); + } } } - } + #else + // Emscripten doesn't support glfwGetKeyName. Just pass the value through. + #endif if (key == GLFW_KEY_UNKNOWN) return;