diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index f5cd03abe..c17b8b477 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -162,7 +162,7 @@ int GlfwApplication::exec() { } void GlfwApplication::staticKeyEvent(GLFWwindow*, int key, int, int action, int mods) { - KeyEvent e(static_cast(key), {static_cast(mods)}); + KeyEvent e(static_cast(key), {static_cast(mods)}, action == GLFW_REPEAT); if(action == GLFW_PRESS) { _instance->keyPressEvent(e); diff --git a/src/Magnum/Platform/GlfwApplication.h b/src/Magnum/Platform/GlfwApplication.h index 008281d24..63c44e4a0 100644 --- a/src/Magnum/Platform/GlfwApplication.h +++ b/src/Magnum/Platform/GlfwApplication.h @@ -750,13 +750,22 @@ class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent { /** @brief Modifiers */ constexpr Modifiers modifiers() const { return _modifiers; } + /** + * @brief Whether the key press is repeated + * + * Returns `true` if the key press event is repeated, `false` if not or + * if this was key release event. + */ + constexpr bool isRepeated() const { return _repeated; } + private: static Modifiers getCurrentGlfwModifiers(GLFWwindow* window); - constexpr KeyEvent(Key key, Modifiers modifiers): _key(key), _modifiers(modifiers) {} + constexpr KeyEvent(Key key, Modifiers modifiers, bool repeated): _key{key}, _modifiers{modifiers}, _repeated{repeated} {} const Key _key; const Modifiers _modifiers; + const bool _repeated; }; /** diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index b316c9cc4..881652409 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -377,7 +377,7 @@ void Sdl2Application::mainLoop() { case SDL_KEYDOWN: case SDL_KEYUP: { - KeyEvent e(static_cast(event.key.keysym.sym), fixedModifiers(event.key.keysym.mod)); + KeyEvent e(static_cast(event.key.keysym.sym), fixedModifiers(event.key.keysym.mod), event.key.repeat != 0); event.type == SDL_KEYDOWN ? keyPressEvent(e) : keyReleaseEvent(e); } break; diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index 24c1b1d24..cf2d4e01d 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -1218,11 +1218,20 @@ class Sdl2Application::KeyEvent: public Sdl2Application::InputEvent { /** @brief Modifiers */ constexpr Modifiers modifiers() const { return _modifiers; } + /** + * @brief Whether the key press is repeated + * + * Returns `true` if the key press event is repeated, `false` if not or + * if this was key release event. + */ + constexpr bool isRepeated() const { return _repeated; } + private: - constexpr KeyEvent(Key key, Modifiers modifiers): _key(key), _modifiers(modifiers) {} + constexpr KeyEvent(Key key, Modifiers modifiers, bool repeated): _key{key}, _modifiers{modifiers}, _repeated{repeated} {} const Key _key; const Modifiers _modifiers; + const bool _repeated; }; /**