From 4cbd84671cc33c87b7f5a48dad63479081f36e22 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 29 Dec 2023 11:29:31 +0100 Subject: [PATCH] impr: Allow num keys to be interpreted as function keys if numlock isn't set Closes #1475 --- main/gui/source/window/window.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 72a09170f..0e275974e 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -1074,6 +1074,7 @@ namespace hex { #if !defined(OS_WEB) // Register key press callback + glfwSetInputMode(m_window, GLFW_LOCK_KEY_MODS, GLFW_TRUE); glfwSetKeyCallback(m_window, [](GLFWwindow *window, int key, int scanCode, int action, int mods) { hex::unused(mods); @@ -1100,6 +1101,19 @@ namespace hex { ) { auto win = static_cast(glfwGetWindowUserPointer(window)); win->m_unlockFrameRate = true; + + if (!(mods & GLFW_MOD_NUM_LOCK)) { + if (key == GLFW_KEY_KP_0) key = GLFW_KEY_INSERT; + else if (key == GLFW_KEY_KP_1) key = GLFW_KEY_END; + else if (key == GLFW_KEY_KP_2) key = GLFW_KEY_DOWN; + else if (key == GLFW_KEY_KP_3) key = GLFW_KEY_PAGE_DOWN; + else if (key == GLFW_KEY_KP_4) key = GLFW_KEY_LEFT; + else if (key == GLFW_KEY_KP_6) key = GLFW_KEY_RIGHT; + else if (key == GLFW_KEY_KP_7) key = GLFW_KEY_HOME; + else if (key == GLFW_KEY_KP_8) key = GLFW_KEY_UP; + else if (key == GLFW_KEY_KP_9) key = GLFW_KEY_PAGE_UP; + } + win->m_pressedKeys.push_back(key); } }