Skip to content

Commit 51c64d8

Browse files
committed
Backends: move io.AddKeyModsEvent() next to io.AddKeyEvent() submission, rely on mods from platform/source. (#4858) + fix #2622 again broken by 746c9f7
Build all
1 parent eb82365 commit 51c64d8

7 files changed

+70
-67
lines changed

backends/imgui_impl_allegro5.cpp

+17-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
// CHANGELOG
1919
// (minor and older changes stripped away, please see git history for details)
20+
// 2022-01-17: Inputs: always calling io.AddKeyModsEvent() next to a key event (not in NewFrame) to fix input queue with very low framerates.
2021
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
2122
// 2021-12-08: Renderer: Fixed mishandling of the the ImDrawCmd::IdxOffset field! This is an old bug but it never had an effect until some internal rendering changes in 1.86.
2223
// 2021-08-17: Calling io.AddFocusEvent() on ALLEGRO_EVENT_DISPLAY_SWITCH_OUT/ALLEGRO_EVENT_DISPLAY_SWITCH_IN events.
@@ -440,6 +441,20 @@ void ImGui_ImplAllegro5_Shutdown()
440441
IM_DELETE(bd);
441442
}
442443

444+
// ev->keyboard.modifiers seems always zero so using that...
445+
static void ImGui_ImplAllegro5_UpdateKeyModifiers()
446+
{
447+
ImGuiIO& io = ImGui::GetIO();
448+
ALLEGRO_KEYBOARD_STATE keys;
449+
al_get_keyboard_state(&keys);
450+
ImGuiKeyModFlags key_mods =
451+
((al_key_down(&keys, ALLEGRO_KEY_LCTRL) || al_key_down(&keys, ALLEGRO_KEY_RCTRL)) ? ImGuiKeyModFlags_Ctrl : 0) |
452+
((al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT)) ? ImGuiKeyModFlags_Shift : 0) |
453+
((al_key_down(&keys, ALLEGRO_KEY_ALT) || al_key_down(&keys, ALLEGRO_KEY_ALTGR)) ? ImGuiKeyModFlags_Alt : 0) |
454+
((al_key_down(&keys, ALLEGRO_KEY_LWIN) || al_key_down(&keys, ALLEGRO_KEY_RWIN)) ? ImGuiKeyModFlags_Super : 0);
455+
io.AddKeyModsEvent(key_mods);
456+
}
457+
443458
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
444459
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
445460
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
@@ -490,6 +505,7 @@ bool ImGui_ImplAllegro5_ProcessEvent(ALLEGRO_EVENT* ev)
490505
ImGuiKey key = ImGui_ImplAllegro5_KeyCodeToImGuiKey(ev->keyboard.keycode);
491506
io.AddKeyEvent(key, (ev->type == ALLEGRO_EVENT_KEY_DOWN));
492507
io.SetKeyEventNativeData(key, ev->keyboard.keycode, -1); // To support legacy indexing (<1.87 user code)
508+
ImGui_ImplAllegro5_UpdateKeyModifiers();
493509
}
494510
return true;
495511
case ALLEGRO_EVENT_DISPLAY_SWITCH_OUT:
@@ -560,15 +576,6 @@ void ImGui_ImplAllegro5_NewFrame()
560576
io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1.0f / 60.0f);
561577
bd->Time = current_time;
562578

563-
// Setup inputs
564-
ALLEGRO_KEYBOARD_STATE keys;
565-
al_get_keyboard_state(&keys);
566-
ImGuiKeyModFlags key_mods =
567-
((al_key_down(&keys, ALLEGRO_KEY_LCTRL) || al_key_down(&keys, ALLEGRO_KEY_RCTRL)) ? ImGuiKeyModFlags_Ctrl : 0) |
568-
((al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT)) ? ImGuiKeyModFlags_Shift : 0) |
569-
((al_key_down(&keys, ALLEGRO_KEY_ALT) || al_key_down(&keys, ALLEGRO_KEY_ALTGR)) ? ImGuiKeyModFlags_Alt : 0) |
570-
((al_key_down(&keys, ALLEGRO_KEY_LWIN) || al_key_down(&keys, ALLEGRO_KEY_RWIN)) ? ImGuiKeyModFlags_Super : 0);
571-
io.AddKeyModsEvent(key_mods);
572-
579+
// Setup mouse cursor shape
573580
ImGui_ImplAllegro5_UpdateMouseCursor();
574581
}

backends/imgui_impl_glfw.cpp

+14-13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
// CHANGELOG
1818
// (minor and older changes stripped away, please see git history for details)
19+
// 2022-01-17: Inputs: always calling io.AddKeyModsEvent() next to a key event (not in NewFrame) to fix input queue with very low framerates.
1920
// 2022-01-12: *BREAKING CHANGE*: Now using glfwSetCursorPosCallback(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetCursorPosCallback() and forward it to the backend via ImGui_ImplGlfw_CursorPosCallback().
2021
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
2122
// 2022-01-05: Inputs: Converting GLFW untranslated keycodes back to translated keycodes (in the ImGui_ImplGlfw_KeyCallback() function) in order to match the behavior of every other backend, and facilitate the use of GLFW with lettered-shortcuts API.
@@ -238,6 +239,17 @@ static ImGuiKey ImGui_ImplGlfw_KeyToImGuiKey(int key)
238239
}
239240
}
240241

242+
static void ImGui_ImplGlfw_UpdateKeyModifiers(int mods)
243+
{
244+
ImGuiIO& io = ImGui::GetIO();
245+
ImGuiKeyModFlags key_mods =
246+
((mods & GLFW_MOD_CONTROL) ? ImGuiKeyModFlags_Ctrl : 0) |
247+
((mods & GLFW_MOD_SHIFT) ? ImGuiKeyModFlags_Shift : 0) |
248+
((mods & GLFW_MOD_ALT) ? ImGuiKeyModFlags_Alt : 0) |
249+
((mods & GLFW_MOD_SUPER) ? ImGuiKeyModFlags_Super : 0);
250+
io.AddKeyModsEvent(key_mods);
251+
}
252+
241253
void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
242254
{
243255
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
@@ -246,6 +258,7 @@ void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int acti
246258

247259
if (action == GLFW_PRESS && button >= 0 && button < IM_ARRAYSIZE(bd->MouseJustPressed))
248260
bd->MouseJustPressed[button] = true;
261+
ImGui_ImplGlfw_UpdateKeyModifiers(mods);
249262
}
250263

251264
void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
@@ -299,6 +312,7 @@ void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int keycode, int scancode, i
299312
ImGuiKey imgui_key = ImGui_ImplGlfw_KeyToImGuiKey(keycode);
300313
io.AddKeyEvent(imgui_key, (action == GLFW_PRESS));
301314
io.SetKeyEventNativeData(imgui_key, keycode, scancode); // To support legacy indexing (<1.87 user code)
315+
ImGui_ImplGlfw_UpdateKeyModifiers(mods);
302316
}
303317

304318
void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused)
@@ -557,18 +571,6 @@ static void ImGui_ImplGlfw_UpdateGamepads()
557571
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
558572
}
559573

560-
static void ImGui_ImplGlfw_UpdateKeyModifiers()
561-
{
562-
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
563-
ImGuiIO& io = ImGui::GetIO();
564-
ImGuiKeyModFlags key_mods =
565-
(((glfwGetKey(bd->Window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) || (glfwGetKey(bd->Window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS)) ? ImGuiKeyModFlags_Ctrl : 0) |
566-
(((glfwGetKey(bd->Window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) || (glfwGetKey(bd->Window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS)) ? ImGuiKeyModFlags_Shift : 0) |
567-
(((glfwGetKey(bd->Window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS) || (glfwGetKey(bd->Window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS)) ? ImGuiKeyModFlags_Alt : 0) |
568-
(((glfwGetKey(bd->Window, GLFW_KEY_LEFT_SUPER) == GLFW_PRESS) || (glfwGetKey(bd->Window, GLFW_KEY_RIGHT_SUPER) == GLFW_PRESS)) ? ImGuiKeyModFlags_Super : 0);
569-
io.AddKeyModsEvent(key_mods);
570-
}
571-
572574
void ImGui_ImplGlfw_NewFrame()
573575
{
574576
ImGuiIO& io = ImGui::GetIO();
@@ -589,7 +591,6 @@ void ImGui_ImplGlfw_NewFrame()
589591
io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1.0f / 60.0f);
590592
bd->Time = current_time;
591593

592-
ImGui_ImplGlfw_UpdateKeyModifiers();
593594
ImGui_ImplGlfw_UpdateMouseData();
594595
ImGui_ImplGlfw_UpdateMouseCursor();
595596

backends/imgui_impl_glut.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void ImGui_ImplGLUT_NewFrame()
202202
ImGui::NewFrame();
203203
}
204204

205-
static void ImGui_ImplGLUT_UpdateKeyboardMods()
205+
static void ImGui_ImplGLUT_UpdateKeyModifiers()
206206
{
207207
ImGuiIO& io = ImGui::GetIO();
208208
int glut_key_mods = glutGetModifiers();
@@ -230,7 +230,7 @@ void ImGui_ImplGLUT_KeyboardFunc(unsigned char c, int x, int y)
230230

231231
ImGuiKey key = ImGui_ImplGLUT_KeyToImGuiKey(c);
232232
ImGui_ImplGLUT_AddKeyEvent(key, true, c);
233-
ImGui_ImplGLUT_UpdateKeyboardMods();
233+
ImGui_ImplGLUT_UpdateKeyModifiers();
234234
(void)x; (void)y; // Unused
235235
}
236236

@@ -239,7 +239,7 @@ void ImGui_ImplGLUT_KeyboardUpFunc(unsigned char c, int x, int y)
239239
//printf("char_up_func %d '%c'\n", c, c);
240240
ImGuiKey key = ImGui_ImplGLUT_KeyToImGuiKey(c);
241241
ImGui_ImplGLUT_AddKeyEvent(key, false, c);
242-
ImGui_ImplGLUT_UpdateKeyboardMods();
242+
ImGui_ImplGLUT_UpdateKeyModifiers();
243243
(void)x; (void)y; // Unused
244244
}
245245

@@ -248,7 +248,7 @@ void ImGui_ImplGLUT_SpecialFunc(int key, int x, int y)
248248
//printf("key_down_func %d\n", key);
249249
ImGuiKey imgui_key = ImGui_ImplGLUT_KeyToImGuiKey(key + 256);
250250
ImGui_ImplGLUT_AddKeyEvent(imgui_key, true, key + 256);
251-
ImGui_ImplGLUT_UpdateKeyboardMods();
251+
ImGui_ImplGLUT_UpdateKeyModifiers();
252252
(void)x; (void)y; // Unused
253253
}
254254

@@ -257,7 +257,7 @@ void ImGui_ImplGLUT_SpecialUpFunc(int key, int x, int y)
257257
//printf("key_up_func %d\n", key);
258258
ImGuiKey imgui_key = ImGui_ImplGLUT_KeyToImGuiKey(key + 256);
259259
ImGui_ImplGLUT_AddKeyEvent(imgui_key, false, key + 256);
260-
ImGui_ImplGLUT_UpdateKeyboardMods();
260+
ImGui_ImplGLUT_UpdateKeyModifiers();
261261
(void)x; (void)y; // Unused
262262
}
263263

backends/imgui_impl_osx.mm

+6-15
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
static bool g_MouseCursorHidden = false;
5454
static bool g_MouseJustPressed[ImGuiMouseButton_COUNT] = {};
5555
static bool g_MouseDown[ImGuiMouseButton_COUNT] = {};
56-
static ImGuiKeyModFlags g_KeyModifiers = ImGuiKeyModFlags_None;
5756
static ImFocusObserver* g_FocusObserver = nil;
5857
static KeyEventResponder* g_KeyEventResponder = nil;
5958
static NSTextInputContext* g_InputContext = nil;
@@ -535,12 +534,6 @@ static void ImGui_ImplOSX_UpdateGamepads()
535534
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
536535
}
537536

538-
static void ImGui_ImplOSX_UpdateKeyModifiers()
539-
{
540-
ImGuiIO& io = ImGui::GetIO();
541-
io.AddKeyModsEvent(g_KeyModifiers);
542-
}
543-
544537
static void ImGui_ImplOSX_UpdateImePosWithView(NSView* view)
545538
{
546539
ImGuiIO& io = ImGui::GetIO();
@@ -569,7 +562,6 @@ void ImGui_ImplOSX_NewFrame(NSView* view)
569562
io.DeltaTime = (float)(current_time - g_Time);
570563
g_Time = current_time;
571564

572-
ImGui_ImplOSX_UpdateKeyModifiers();
573565
ImGui_ImplOSX_UpdateMouseCursorAndButtons();
574566
ImGui_ImplOSX_UpdateGamepads();
575567
ImGui_ImplOSX_UpdateImePosWithView(view);
@@ -666,17 +658,16 @@ bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view)
666658
unsigned short key_code = [event keyCode];
667659
unsigned int flags = [event modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask;
668660

669-
ImGuiKeyModFlags imgui_flags = ImGuiKeyModFlags_None;
661+
ImGuiKeyModFlags imgui_key_mods = ImGuiKeyModFlags_None;
670662
if (flags & NSEventModifierFlagShift)
671-
imgui_flags |= ImGuiKeyModFlags_Shift;
663+
imgui_key_mods |= ImGuiKeyModFlags_Shift;
672664
if (flags & NSEventModifierFlagControl)
673-
imgui_flags |= ImGuiKeyModFlags_Ctrl;
665+
imgui_key_mods |= ImGuiKeyModFlags_Ctrl;
674666
if (flags & NSEventModifierFlagOption)
675-
imgui_flags |= ImGuiKeyModFlags_Alt;
667+
imgui_key_mods |= ImGuiKeyModFlags_Alt;
676668
if (flags & NSEventModifierFlagCommand)
677-
imgui_flags |= ImGuiKeyModFlags_Super;
678-
679-
g_KeyModifiers = imgui_flags;
669+
imgui_key_mods |= ImGuiKeyModFlags_Super;
670+
io.AddKeyModsEvent(imgui_key_mods);
680671

681672
ImGuiKey key = ImGui_ImplOSX_KeyCodeToImGuiKey(key_code);
682673
if (key != ImGuiKey_None)

backends/imgui_impl_sdl.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
// CHANGELOG
2020
// (minor and older changes stripped away, please see git history for details)
21+
// 2022-01-17: Inputs: always calling io.AddKeyModsEvent() next to a key event (not in NewFrame) to fix input queue with very low framerates.
2122
// 2022-01-12: Update mouse inputs using SDL_MOUSEMOTION/SDL_WINDOWEVENT_LEAVE + fallback to provide it when focused but not hovered/captured. More standard and will allow us to pass it to future input queue API.
2223
// 2022-01-12: Maintain our own copy of MouseButtonsDown mask instead of using ImGui::IsAnyMouseDown() which will be obsoleted.
2324
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
@@ -222,6 +223,17 @@ static ImGuiKey ImGui_ImplSDL2_KeycodeToImGuiKey(int keycode)
222223
return ImGuiKey_None;
223224
}
224225

226+
static void ImGui_ImplSDL2_UpdateKeyModifiers(SDL_Keymod sdl_key_mods)
227+
{
228+
ImGuiIO& io = ImGui::GetIO();
229+
ImGuiKeyModFlags key_mods =
230+
((sdl_key_mods & KMOD_CTRL) ? ImGuiKeyModFlags_Ctrl : 0) |
231+
((sdl_key_mods & KMOD_SHIFT) ? ImGuiKeyModFlags_Shift : 0) |
232+
((sdl_key_mods & KMOD_ALT) ? ImGuiKeyModFlags_Alt : 0) |
233+
((sdl_key_mods & KMOD_GUI) ? ImGuiKeyModFlags_Super : 0);
234+
io.AddKeyModsEvent(key_mods);
235+
}
236+
225237
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
226238
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
227239
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
@@ -272,6 +284,7 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
272284
ImGuiKey key = ImGui_ImplSDL2_KeycodeToImGuiKey(event->key.keysym.sym);
273285
io.AddKeyEvent(key, (event->type == SDL_KEYDOWN));
274286
io.SetKeyEventNativeData(key, event->key.keysym.sym, event->key.keysym.scancode, event->key.keysym.scancode); // To support legacy indexing (<1.87 user code). Legacy backend uses SDLK_*** as indices to IsKeyXXX() functions.
287+
ImGui_ImplSDL2_UpdateKeyModifiers((SDL_Keymod)event->key.keysym.mod);
275288
return true;
276289
}
277290
case SDL_WINDOWEVENT:
@@ -499,18 +512,6 @@ static void ImGui_ImplSDL2_UpdateGamepads()
499512
#undef MAP_ANALOG
500513
}
501514

502-
static void ImGui_ImplSDL2_UpdateKeyModifiers()
503-
{
504-
ImGuiIO& io = ImGui::GetIO();
505-
SDL_Keymod sdl_key_mods = SDL_GetModState();
506-
ImGuiKeyModFlags key_mods =
507-
((sdl_key_mods & KMOD_CTRL) ? ImGuiKeyModFlags_Ctrl : 0) |
508-
((sdl_key_mods & KMOD_SHIFT) ? ImGuiKeyModFlags_Shift : 0) |
509-
((sdl_key_mods & KMOD_ALT) ? ImGuiKeyModFlags_Alt : 0) |
510-
((sdl_key_mods & KMOD_GUI) ? ImGuiKeyModFlags_Super : 0);
511-
io.AddKeyModsEvent(key_mods);
512-
}
513-
514515
void ImGui_ImplSDL2_NewFrame()
515516
{
516517
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
@@ -534,7 +535,6 @@ void ImGui_ImplSDL2_NewFrame()
534535
io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / frequency) : (float)(1.0f / 60.0f);
535536
bd->Time = current_time;
536537

537-
ImGui_ImplSDL2_UpdateKeyModifiers();
538538
ImGui_ImplSDL2_UpdateMouseData();
539539
ImGui_ImplSDL2_UpdateMouseCursor();
540540

backends/imgui_impl_win32.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ typedef DWORD (WINAPI *PFN_XInputGetState)(DWORD, XINPUT_STATE*);
3434

3535
// CHANGELOG
3636
// (minor and older changes stripped away, please see git history for details)
37-
// 2022-01-12: Update mouse inputs using WM_MOUSEMOVE/WM_MOUSELEAVE + fallback to provide it when focused but not hovered/captured. More standard and will allow us to pass it to future input queue API.
38-
// 2022-01-12: Maintain our own copy of MouseButtonsDown mask instead of using ImGui::IsAnyMouseDown() which will be obsoleted.
37+
// 2022-01-17: Inputs: always calling io.AddKeyModsEvent() next to a key event (not in NewFrame) to fix input queue with very low framerates.
38+
// 2022-01-12: Inputs: Update mouse inputs using WM_MOUSEMOVE/WM_MOUSELEAVE + fallback to provide it when focused but not hovered/captured. More standard and will allow us to pass it to future input queue API.
39+
// 2022-01-12: Inputs: Maintain our own copy of MouseButtonsDown mask instead of using ImGui::IsAnyMouseDown() which will be obsoleted.
3940
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
4041
// 2021-12-16: Inputs: Fill VK_LCONTROL/VK_RCONTROL/VK_LSHIFT/VK_RSHIFT/VK_LMENU/VK_RMENU for completeness.
4142
// 2021-08-17: Calling io.AddFocusEvent() on WM_SETFOCUS/WM_KILLFOCUS messages.
@@ -235,10 +236,10 @@ static void ImGui_ImplWin32_UpdateKeyModifiers()
235236
{
236237
ImGuiIO& io = ImGui::GetIO();
237238
ImGuiKeyModFlags key_mods =
238-
((IsVkDown(VK_LCONTROL) || IsVkDown(VK_RCONTROL)) ? ImGuiKeyModFlags_Ctrl : 0) |
239-
((IsVkDown(VK_LSHIFT) || IsVkDown(VK_RSHIFT)) ? ImGuiKeyModFlags_Shift : 0) |
240-
((IsVkDown(VK_LMENU) || IsVkDown(VK_RMENU)) ? ImGuiKeyModFlags_Alt : 0) |
241-
((IsVkDown(VK_LWIN) || IsVkDown(VK_RWIN)) ? ImGuiKeyModFlags_Super : 0);
239+
((IsVkDown(VK_CONTROL)) ? ImGuiKeyModFlags_Ctrl : 0) |
240+
((IsVkDown(VK_SHIFT) ) ? ImGuiKeyModFlags_Shift : 0) |
241+
((IsVkDown(VK_MENU)) ? ImGuiKeyModFlags_Alt : 0) |
242+
((IsVkDown(VK_APPS)) ? ImGuiKeyModFlags_Super : 0);
242243
io.AddKeyModsEvent(key_mods);
243244
}
244245

@@ -342,9 +343,6 @@ void ImGui_ImplWin32_NewFrame()
342343
// Process workarounds for known Windows key handling issues
343344
ImGui_ImplWin32_ProcessKeyEventsWorkarounds();
344345

345-
// Update key modifiers
346-
ImGui_ImplWin32_UpdateKeyModifiers();
347-
348346
// Update OS mouse cursor with the cursor requested by imgui
349347
ImGuiMouseCursor mouse_cursor = io.MouseDrawCursor ? ImGuiMouseCursor_None : ImGui::GetMouseCursor();
350348
if (bd->LastMouseCursor != mouse_cursor)
@@ -564,7 +562,6 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA
564562
case WM_SYSKEYUP:
565563
{
566564
const bool is_key_down = (msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN);
567-
568565
if (wParam < 256)
569566
{
570567
// Obtain virtual key code
@@ -579,6 +576,9 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA
579576
if (key != ImGuiKey_None)
580577
ImGui_ImplWin32_AddKeyEvent(key, is_key_down, vk, scancode);
581578

579+
// Submit modifiers
580+
ImGui_ImplWin32_UpdateKeyModifiers();
581+
582582
// Submit individual left/right modifier events
583583
if (vk == VK_SHIFT)
584584
{

docs/CHANGELOG.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,17 @@ Other Changes:
103103
- Backends: GLFW: Pass localized keys (matching keyboard layout). Fix e.g. CTRL+A, CTRL+Z, CTRL+Y shortcuts.
104104
We are now converting GLFW untranslated keycodes back to translated keycodes in order to match the behavior of every
105105
other backend, and facilitate the use of GLFW with lettered-shortcuts API. (#456, #2625)
106+
- Backends: GLFW: Submit keys using io.AddKeyEvent(). Submit keymods using io.AddKeyModsEvent() at the same time. (#2625)
106107
- Backends: GLFW: Update mouse position using glfwSetCursorPosCallback() + fallback when focused but not hovered/captured.
108+
- Backends: Win32: Submit keys using io.AddKeyEvent(). Submit keymods using io.AddKeyModsEvent() at the same time. (#2625)
107109
- Backends: Win32: Update mouse position using WM_MOUSEMOVE/WM_MOUSELEAVE + fallback when focused but not hovered/captured.
108110
- Backends: Win32: Maintain a MouseButtonsDown mask instead of using ImGui::IsAnyMouseDown() which will be obsoleted.
109111
- Backends: SDL: Pass localized keys (matching keyboard layout). Fix e.g. CTRL+A, CTRL+Z, CTRL+Y shortcuts.
112+
- Backends: SDL: Submit keys using io.AddKeyEvent(). Submit keymods using io.AddKeyModsEvent() at the same time. (#2625)
110113
- Backends: SDL: Update mouse position using SDL_MOUSEMOTION/SDL_WINDOWEVENT_LEAVE + fallback when focused but not hovered/captured.
111114
- Backends: SDL: Maintain a MouseButtonsDown mask instead of using ImGui::IsAnyMouseDown() which will be obsoleted.
112-
- Backends: Allegro5, GLFW, GLUT, SDL, OSX, Win32, Android: Updated to use io.AddKeyEvent() with full key range. (#2625) [@thedmd]
115+
- Backends: Allegro5: Submit keys using io.AddKeyEvent(). Submit keymods using io.AddKeyModsEvent() at the same time. (#2625)
116+
- Backends: Android, GLUT, OSX: Submit keys using io.AddKeyEvent(). Submit keymods using io.AddKeyModsEvent() at the same time. (#2625)
113117
- Backends: OpenGL3: Fixed a buffer overflow in imgui_impl_opengl3_loader.h init (added in 1.86). (#4468, #4830) [@dymk]
114118
It would generally not have noticeable side-effect at runtime but would be detected by runtime checkers.
115119
- Backends: Metal: Added Apple Metal C++ API support. (#4824, #4746) [@luigifcruz]

0 commit comments

Comments
 (0)