ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
60.63k stars 10.24k forks source link

ImGui doesn't detect keyboard input #4617

Closed Adam-Miszczak closed 3 years ago

Adam-Miszczak commented 3 years ago

v1.80 (WIP) master branch DirectX 11, Windows 10

ImGui_ImplWin32 ImGui_ImplDX11

ImGui isn't detecting keyboard inputs. The mouse works perfectly fine and I can double click on various widgets to prompt a keyboard input but no matter which keys I press nothing happens. In the demo window under 'Inputs, Navigation & Focus' I can see that the wantcapturekeyboard and wanttextinput flags are 1, but no keys appear under the 'keys pressed' or 'keys down' sections when a key is pressed.

Here is how I initialize ImGui:

        ImGui_ImplWin32_EnableDpiAwareness();
    IMGUI_CHECKVERSION();
    ImGui::CreateContext();

    ImGuiIO& io = ImGui::GetIO(); (void)io;
    ImGuiStyle& style = ImGui::GetStyle();
    io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;

    ImGui::StyleColorsClassic();
    pFont = io.Fonts->AddFontFromFileTTF("assets/fonts/Tahoma.ttf", 14);

    ImGui_ImplWin32_Init(hwnd);
    ImGui_ImplDX11_Init(m_D3D->GetDevice(), m_D3D->GetDeviceContext());

And here is my WndProc function

extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

LRESULT CALLBACK WndProc( HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam ) {
    if (ImGui_ImplWin32_WndProcHandler( hwnd, umessage, wparam, lparam )) return true;

    switch ( umessage ) {
        case WM_DESTROY: {
            PostQuitMessage(0);
            return 0;
        } break;

        case WM_CLOSE: {
            PostQuitMessage(0);
            return 0;
        } break;

        default: {
            return ApplicationHandle->MessageHandler( hwnd, umessage, wparam, lparam );
        }
    }

    return ::DefWindowProc(hwnd, umessage, wparam, lparam);
}
Adam-Miszczak commented 3 years ago

I haved fixed this by setting the cooperative level of my keyboard device to DISCL_NONEXCLUSIVE