Skip to content

Commit

Permalink
Workaround for win32 not sending WM_KEYUP for VK_LWIN/VK_RWIN in some…
Browse files Browse the repository at this point in the history
… cases. Fixes ocornut#2976.

Issue can be observed if we press WinKey+v when win32/SDL/GLFW window is focused. Application would get stuck in a state thinking WinKey is pressed even after it was released.
  • Loading branch information
rokups committed Jan 13, 2020
1 parent 52334ad commit a239660
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions examples/imgui_impl_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,11 @@ void ImGui_ImplGlfw_NewFrame()

// Update game controllers (if enabled and available)
ImGui_ImplGlfw_UpdateGamepads();

#ifdef _WIN32
// Workaround for issue https://github.com/ocornut/imgui/issues/2976 (upstream issue https://github.com/glfw/glfw/issues/1622).
io.KeysDown[GLFW_KEY_LEFT_SUPER] &= (::GetKeyState(VK_LWIN) & 0x8000) != 0;
io.KeysDown[GLFW_KEY_RIGHT_SUPER] &= (::GetKeyState(VK_RWIN) & 0x8000) != 0;
io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER];
#endif
}
7 changes: 7 additions & 0 deletions examples/imgui_impl_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,11 @@ void ImGui_ImplSDL2_NewFrame(SDL_Window* window)

// Update game controllers (if enabled and available)
ImGui_ImplSDL2_UpdateGamepads();

#ifdef _WIN32
// Workaround for issue https://github.com/ocornut/imgui/issues/2976 (upstream issue https://bugzilla.libsdl.org/show_bug.cgi?id=4939).
io.KeysDown[SDL_SCANCODE_LGUI] &= (::GetKeyState(VK_LWIN) & 0x8000) != 0;
io.KeysDown[SDL_SCANCODE_RGUI] &= (::GetKeyState(VK_RWIN) & 0x8000) != 0;
io.KeySuper = io.KeysDown[SDL_SCANCODE_LGUI] || io.KeysDown[SDL_SCANCODE_RGUI];
#endif
}
5 changes: 4 additions & 1 deletion examples/imgui_impl_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ void ImGui_ImplWin32_NewFrame()
io.KeyCtrl = (::GetKeyState(VK_CONTROL) & 0x8000) != 0;
io.KeyShift = (::GetKeyState(VK_SHIFT) & 0x8000) != 0;
io.KeyAlt = (::GetKeyState(VK_MENU) & 0x8000) != 0;
io.KeySuper = false;
// Workaround for issue https://github.com/ocornut/imgui/issues/2976 (win32 does not send VK_KEYUP sometimes).
io.KeysDown[VK_LWIN] &= (::GetKeyState(VK_LWIN) & 0x8000) != 0;
io.KeysDown[VK_RWIN] &= (::GetKeyState(VK_RWIN) & 0x8000) != 0;
io.KeySuper = io.KeysDown[VK_LWIN] || io.KeysDown[VK_RWIN];
// io.KeysDown[], io.MousePos, io.MouseDown[], io.MouseWheel: filled by the WndProc handler below.

// Update OS mouse position
Expand Down

0 comments on commit a239660

Please sign in to comment.