Quick answer: Before handling game input, check ImGui::GetIO().WantCaptureMouse and WantCaptureKeyboard. If true, ImGui owns that input — skip game handling.
Clicking a Dear ImGui debug button also fires a game action behind it. The game input layer doesn’t know ImGui wanted that click.
Gate Game Input
ImGuiIO& io = ImGui::GetIO();
if (!io.WantCaptureMouse) {
HandleGameMouseInput(); // only when ImGui doesn't want it
}
if (!io.WantCaptureKeyboard) {
HandleGameKeyboardInput();
}
WantCaptureMouse is true when the cursor is over an ImGui window or dragging a widget. WantCaptureKeyboard is true when an ImGui text field is focused.
Order Matters
Call ImGui::NewFrame() and build your ImGui UI before reading the Want flags — they reflect the current frame’s widget state. Then process game input.
Feed Events to ImGui First
Your platform backend (imgui_impl_sdl, imgui_impl_glfw) must receive OS events before you decide. Pump events → ImGui processes them → flags update → you gate game input.
Text Input
io.WantTextInput is the finer-grained flag for “an ImGui text field wants character input” — useful if your game has its own text entry.
Verifying
Click ImGui buttons — only the button reacts. Click the game viewport — only the game reacts. Typing in an ImGui field doesn’t trigger game hotkeys.
“ImGui tells you when it wants input. Always check the Want flags before handling game input.”
Wrap this in your input layer once — a single InputManager that consults ImGui’s flags means individual systems never have to think about it.