diff --git a/README.md b/README.md index c912c6257..f7084ed54 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ The following dependencies are needed by the examples and test programs: ## Changelog + - Added `mods` parameter to character callback - Added `GLFWcursor` custom system cursor handle - Added `glfwCreateCursor`, `glfwDestroyCursor` and `glfwSetCursor` for managing custom system cursors diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 0c234d9d1..b43081142 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -776,12 +776,14 @@ typedef void (* GLFWkeyfun)(GLFWwindow*,int,int,int,int); * * @param[in] window The window that received the event. * @param[in] codepoint The Unicode code point of the character. + * @param[in] mods Bit field describing which [modifier keys](@ref mods) were + * held down. * * @sa glfwSetCharCallback * * @ingroup input */ -typedef void (* GLFWcharfun)(GLFWwindow*,unsigned int); +typedef void (* GLFWcharfun)(GLFWwindow*,unsigned int,int); /*! @brief The function signature for file drop callbacks. diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 20af25c14..a2c57f2bc 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -611,7 +611,7 @@ static int translateKey(unsigned int key) NSUInteger i, length = [characters length]; for (i = 0; i < length; i++) - _glfwInputChar(window, [characters characterAtIndex:i]); + _glfwInputChar(window, [characters characterAtIndex:i], mods); } - (void)flagsChanged:(NSEvent *)event diff --git a/src/input.c b/src/input.c index 84da9f1dd..33882ecda 100644 --- a/src/input.c +++ b/src/input.c @@ -153,13 +153,13 @@ void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int m window->callbacks.key((GLFWwindow*) window, key, scancode, action, mods); } -void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint) +void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint, int mods) { if (codepoint < 32 || (codepoint > 126 && codepoint < 160)) return; if (window->callbacks.character) - window->callbacks.character((GLFWwindow*) window, codepoint); + window->callbacks.character((GLFWwindow*) window, codepoint, mods); } void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset) diff --git a/src/internal.h b/src/internal.h index 319f7064b..71dc132f1 100644 --- a/src/internal.h +++ b/src/internal.h @@ -682,9 +682,10 @@ void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int m /*! @brief Notifies shared code of a Unicode character input event. * @param[in] window The window that received the event. * @param[in] codepoint The Unicode code point of the input character. + * @param[in] mods The modifiers pressed when the event was generated. * @ingroup event */ -void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint); +void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint, int mods); /*! @brief Notifies shared code of a scroll event. * @param[in] window The window that received the event. diff --git a/src/win32_window.c b/src/win32_window.c index e6a6e13d2..d5fa504ee 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -528,7 +528,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, case WM_CHAR: case WM_SYSCHAR: { - _glfwInputChar(window, (unsigned int) wParam); + _glfwInputChar(window, (unsigned int) wParam, getKeyMods()); return 0; } @@ -543,7 +543,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, return TRUE; } - _glfwInputChar(window, (unsigned int) wParam); + _glfwInputChar(window, (unsigned int) wParam, getKeyMods()); return FALSE; } diff --git a/src/x11_window.c b/src/x11_window.c index 09d5fbd7b..b1cbccb3a 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -605,7 +605,7 @@ static void processEvent(XEvent *event) _glfwInputKey(window, key, event->xkey.keycode, GLFW_PRESS, mods); if (character != -1) - _glfwInputChar(window, character); + _glfwInputChar(window, character, mods); break; } diff --git a/tests/events.c b/tests/events.c index 234a0a058..56524a46a 100644 --- a/tests/events.c +++ b/tests/events.c @@ -388,12 +388,18 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action, } } -static void char_callback(GLFWwindow* window, unsigned int codepoint) +static void char_callback(GLFWwindow* window, unsigned int codepoint, int mods) { Slot* slot = glfwGetWindowUserPointer(window); - printf("%08x to %i at %0.3f: Character 0x%08x (%s) input\n", + + printf("%08x to %i at %0.3f: Character 0x%08x (%s)", counter++, slot->number, glfwGetTime(), codepoint, get_character_string(codepoint)); + + if (mods) + printf(" (with%s)", get_mods_name(mods)); + + printf(" input\n"); } static void drop_callback(GLFWwindow* window, int count, const char** names)