Skip to main content

Getting ImGuiIO

GetIO

Access the ImGuiIO structure which contains mouse/keyboard/gamepad inputs, time, various configuration options/flags.
ImGuiIO&
Reference to the current context’s IO structure
Example:

Input Functions

Backends should call these functions to submit input events. Application code typically only reads the resulting state.

AddKeyEvent

Queue a new key down/up event.
ImGuiKey
Key identifier (e.g., ImGuiKey_A, ImGuiKey_Space)
bool
True for key down, false for key up

AddKeyAnalogEvent

Queue a key down/up event for analog values (e.g., gamepad triggers).
float
Analog value (typically 0.0f to 1.0f)

AddMousePosEvent

Queue a mouse position update. Use -FLT_MAX, -FLT_MAX to signify no mouse.
float
Mouse X position
float
Mouse Y position

AddMouseButtonEvent

Queue a mouse button change.
int
Mouse button (0=left, 1=right, 2=middle)
bool
True for button down, false for button up

AddMouseWheelEvent

Queue a mouse wheel update.
float
Horizontal wheel delta (positive = scroll left, negative = scroll right)
float
Vertical wheel delta (positive = scroll up, negative = scroll down)

AddMouseSourceEvent

Queue a mouse source change (Mouse/TouchScreen/Pen).
ImGuiMouseSource
Source identifier (ImGuiMouseSource_Mouse, ImGuiMouseSource_TouchScreen, or ImGuiMouseSource_Pen)

AddFocusEvent

Queue a gain/loss of focus for the application.
bool
True when application gains focus, false when it loses focus

AddInputCharacter

Queue a new character input.
unsigned int
Unicode codepoint

AddInputCharactersUTF8

Queue new characters input from a UTF-8 string.
const char*
UTF-8 encoded string

Input Clearing

ClearEventsQueue

Clear all incoming events.

ClearInputKeys

Clear current keyboard/gamepad state and current frame text input buffer. Equivalent to releasing all keys/buttons.

ClearInputMouse

Clear current mouse state.

Input State Access

Mouse State

ImVec2
Mouse position in pixels. Set to ImVec2(-FLT_MAX, -FLT_MAX) if mouse is unavailable.
bool[5]
Mouse buttons state. Index 0=left, 1=right, 2=middle.
float
Mouse wheel vertical: 1 unit scrolls about 5 lines text.

Keyboard Modifiers

bool
Ctrl modifier down (non-macOS) or Cmd modifier down (macOS).
ImGuiKeyChord
Combined key modifiers flags (updated by NewFrame()).

Want Capture Flags

When reading io.WantCaptureMouse or io.WantCaptureKeyboard to dispatch your inputs, it is generally easier and more correct to use their state BEFORE calling NewFrame().
bool
Set when Dear ImGui will use mouse inputs. In this case, do not dispatch mouse inputs to your game/application.
bool
Set when Dear ImGui will use keyboard inputs. In this case, do not dispatch keyboard inputs to your game/application.
bool
Mobile/console: when set, you may display an on-screen keyboard. Set by Dear ImGui when it wants textual keyboard input.
bool
MousePos has been altered, backend should reposition mouse on next frame. Rarely used! Only when io.ConfigNavMoveSetMousePos is enabled.
Example:

Configuration Fields

See ImGuiIO for complete list of configuration options.

See Also

  • Keyboard - Keyboard input functions
  • Mouse - Mouse input functions
  • Shortcuts - Keyboard shortcuts and input routing
  • ImGuiIO - Complete ImGuiIO structure reference