From 71429d306e747b429ba64cecb3fecadfae599bba Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 14 Apr 2015 09:45:27 +0100 Subject: [PATCH] Examples: Simplified GLFW keyboard callbacks --- examples/opengl3_example/imgui_impl_glfw_gl3.cpp | 14 ++++---------- examples/opengl_example/imgui_impl_glfw.cpp | 14 ++++---------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp index 1a5a09c16..9953a9631 100644 --- a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp +++ b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp @@ -142,16 +142,10 @@ void ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow* window, int key, int, int action, if (action == GLFW_RELEASE) io.KeysDown[key] = false; - bool leftCtrl = glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS; - bool rightCtrl = glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS; - bool leftShift = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS; - bool rightShift = glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; - bool leftAlt = glfwGetKey(window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS; - bool rightAlt = glfwGetKey(window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS; - - io.KeyCtrl = leftCtrl || rightCtrl; - io.KeyShift = leftShift || rightShift; - io.KeyAlt = leftAlt || rightAlt; + (void)mods; // Modifiers are not reliable across systems + io.KeyCtrl = glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS; + io.KeyShift = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; + io.KeyAlt = glfwGetKey(window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS; } void ImGui_ImplGlfwGL3_CharCallback(GLFWwindow*, unsigned int c) diff --git a/examples/opengl_example/imgui_impl_glfw.cpp b/examples/opengl_example/imgui_impl_glfw.cpp index 3babcba15..341d418de 100644 --- a/examples/opengl_example/imgui_impl_glfw.cpp +++ b/examples/opengl_example/imgui_impl_glfw.cpp @@ -124,16 +124,10 @@ void ImGui_ImplGlFw_KeyCallback(GLFWwindow* window, int key, int, int action, in if (action == GLFW_RELEASE) io.KeysDown[key] = false; - bool leftCtrl = glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS; - bool rightCtrl = glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS; - bool leftShift = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS; - bool rightShift = glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; - bool leftAlt = glfwGetKey(window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS; - bool rightAlt = glfwGetKey(window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS; - - io.KeyCtrl = leftCtrl || rightCtrl; - io.KeyShift = leftShift || rightShift; - io.KeyAlt = leftAlt || rightAlt; + (void)mods; // Modifiers are not reliable across systems + io.KeyCtrl = glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS; + io.KeyShift = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; + io.KeyAlt = glfwGetKey(window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS; } void ImGui_ImplGlfw_CharCallback(GLFWwindow*, unsigned int c)