Backends: Win32: ImGuiKey_PrintScreen key down event not emitted. #6859

Closed
opened 2023-09-25 07:29:45 +00:00 by devkaiwang · 4 comments
devkaiwang commented 2023-09-25 07:29:45 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

Version: 1.89.4 WIP (18931)
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_dx12.cpp + imgui_impl_win32.cpp
Compiler: Visual Studio (Version 17.7.4)
Operating System: Windows 11.

My Issue/Question:

"PrintScreen" (VK_SNAPSHOT) key event is ignored by ImGui.

Windows only sends WM_KEYUP when "PrintScreen" key is pressed and no previous WM_KEYDOWN event is triggered. As a result, "PrintScreen" key-up event is just ignored by ImGui_ImplWin32_AddKeyEvent.

We can reproduce this issue using ImGui Demo. In the Inputs section, we press PrintScreen, and no key event is logged:
image

**Version/Branch of Dear ImGui:** Version: 1.89.4 WIP (18931) Branch: docking **Back-end/Renderer/Compiler/OS** Back-ends: imgui_impl_dx12.cpp + imgui_impl_win32.cpp Compiler: Visual Studio (Version 17.7.4) Operating System: Windows 11. **My Issue/Question:** "PrintScreen" (`VK_SNAPSHOT`) key event is ignored by ImGui. Windows only sends `WM_KEYUP` when "PrintScreen" key is pressed and no previous `WM_KEYDOWN` event is triggered. As a result, "PrintScreen" key-up event is just ignored by `ImGui_ImplWin32_AddKeyEvent`. We can reproduce this issue using ImGui Demo. In the **Inputs** section, we press PrintScreen, and no key event is logged: ![image](https://github.com/ocornut/imgui/assets/15721569/fc95cd18-4f86-4ff8-95e2-6f3335a1c6fb)
thedmd commented 2023-09-25 07:42:30 +00:00 (Migrated from github.com)

Windows does not send WM_KEYDOWN for VK_SNAPSHOT, only WM_KEYUP. Workarounds in Windows backend are necessary.

One way to deal with missing message I found is:
https://gamedev.net/forums/topic/693260-vk_snapshot-and-keydown/5361602/

Another is to synthesise key down, when recieving key up.

Windows does not send WM_KEYDOWN for VK_SNAPSHOT, only WM_KEYUP. Workarounds in Windows backend are necessary. One way to deal with missing message I found is: https://gamedev.net/forums/topic/693260-vk_snapshot-and-keydown/5361602/ Another is to synthesise key down, when recieving key up.
devkaiwang commented 2023-09-25 07:59:32 +00:00 (Migrated from github.com)

Hi @thedmd

Yes, I did the second workaround:

if ((key == ImGuiKey_PrintScreen) && !is_key_down)
{
    // Add a key-down event.
    ImGui_ImplWin32_AddKeyEvent(key, true, vk, scancode);
    // Add a key-up event.
    ImGui_ImplWin32_AddKeyEvent(key, false, vk, scancode);
}
Hi @thedmd Yes, I did the second workaround: ```c++ if ((key == ImGuiKey_PrintScreen) && !is_key_down) { // Add a key-down event. ImGui_ImplWin32_AddKeyEvent(key, true, vk, scancode); // Add a key-up event. ImGui_ImplWin32_AddKeyEvent(key, false, vk, scancode); } ```
ocornut commented 2023-09-25 08:26:44 +00:00 (Migrated from github.com)

A PR for the backend would be appreciated, particularly if we can received the Down event at the right time.

A PR for the backend would be appreciated, particularly if we can received the Down event at the right time.
ocornut commented 2023-09-25 08:59:14 +00:00 (Migrated from github.com)

I investigated and realized both GLFW and SDL did the same thing: synthetize key-down at the time for key-up, for this special key. So going along and implementing the same unperfect workaround. Pushed 12ee2dd. Thanks!

I investigated and realized both GLFW and SDL did the same thing: synthetize key-down at the time for key-up, for this special key. So going along and implementing the same unperfect workaround. Pushed 12ee2dd. Thanks!
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#6859
No description provided.