Skip to main content

Input Routing Philosophy

Dear ImGui’s input system is designed around a crucial principle:
Always forward ALL input to Dear ImGui, then check if ImGui wants to use it before passing it to your application.
This allows Dear ImGui to:
  • Detect clicks in empty space to unfocus windows
  • Handle dragging that starts outside widgets
  • Properly manage focus and hover states
  • Provide smooth interaction behavior

The Want Capture Flags

After calling ImGui::NewFrame(), check these flags in ImGuiIO to determine input routing:

io.WantCaptureMouse

Set when Dear ImGui wants to use mouse input:
When is it set?
  • Hovering over any Dear ImGui window
  • Clicking on any Dear ImGui widget
  • Dragging a slider, scrollbar, or window
  • Using mouse wheel over a Dear ImGui window
Don’t manually check if the mouse is over a window! Use io.WantCaptureMouse instead:

io.WantCaptureKeyboard

Set when Dear ImGui wants to use keyboard input:
When is it set?
  • An InputText widget has focus
  • Keyboard navigation is active (io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard)
  • A keyboard shortcut is being processed
Special case: Text input widgets release focus on the “KeyDown” event of Return, so the “KeyUp” event will have io.WantCaptureKeyboard == false. Track which keys were pressed while ImGui had focus if this matters to your application.

io.WantTextInput

Set when Dear ImGui expects text input (useful for on-screen keyboards):
When is it set?
  • An InputText widget is active
  • An InputTextMultiline widget is active

Mouse Input

Mouse Position

Mouse Buttons

Mouse Wheel

Mouse Source (Optional)

Reading Mouse State

Keyboard Input

Key Events (Modern API)

Dear ImGui uses a named key system:

Character Input

For text input, send Unicode characters:
On Windows, use WM_CHAR messages. On other platforms, convert keyboard input to UTF-8/UTF-16 characters.

Reading Keyboard State

Keyboard Shortcuts

Modifier Keys

Gamepad Input

Enable gamepad navigation:

Gamepad Buttons

Gamepad Analog Inputs

You’re responsible for applying dead zones and normalizing analog values. ImGui expects values in the range 0.0 to 1.0.

Focus and Hover Detection

Window Focus

Window Hover

Item Hover and Focus

Custom Input Handling Example

Here’s a complete example of routing input:

IME (Input Method Editor) Support

For languages like Chinese, Japanese, Korean:

Touch Input

Touch input can be mapped to mouse input:
For better touch support:

Common Patterns

Pausing Game When UI is Active

Global Shortcuts

Mouse Delta for Camera

Next Steps