Skip to main content

Overview

Dear ImGui uses the ImGuiKey enum which contains all possible keyboard, mouse, and gamepad inputs. The keyboard key enum values are named after the keys on a standard US keyboard.
Consider using the Shortcut() function instead of IsKeyPressed()/IsKeyChordPressed()! Shortcut() is easier to use and better featured (supports focus routing).

Key State Functions

IsKeyDown

Check if key is being held.
ImGuiKey
Key to check (e.g., ImGuiKey_A, ImGuiKey_Space)
bool
True if key is currently down
Example:

IsKeyPressed

Check if key was pressed (went from !Down to Down).
ImGuiKey
Key to check
bool
default:"true"
If true, returns true on key repeat. Repeat rate uses io.KeyRepeatDelay / io.KeyRepeatRate.
bool
True if key was just pressed or repeating
Example:

IsKeyReleased

Check if key was released (went from Down to !Down).
ImGuiKey
Key to check
bool
True if key was just released

GetKeyPressedAmount

Get a count of key presses using provided repeat rate/delay. Usually returns 0 or 1 but might be >1 if RepeatRate is small enough that DeltaTime > RepeatRate.
ImGuiKey
Key to check
float
Time before repeat starts
float
Repeat rate
int
Number of key presses this frame
Example:

Key Chords

IsKeyChordPressed

Check if a key chord (mods + key) was pressed. This doesn’t do any routing or focus check.
ImGuiKeyChord
Key chord (e.g., ImGuiMod_Ctrl | ImGuiKey_S)
bool
True if the key chord was pressed
Consider using Shortcut() instead, which supports focus routing and is more feature-complete.
Example:

Key Names

GetKeyName

Get English name of the key for debugging purposes.
ImGuiKey
Key to get name for
const char*
Key name string
These names are provided for debugging purposes and are not meant to be saved persistently nor compared.
Example:

Keyboard Capture

SetNextFrameWantCaptureKeyboard

Override io.WantCaptureKeyboard flag next frame. Equivalent to setting io.WantCaptureKeyboard after the next NewFrame() call.
bool
Whether to capture keyboard
Example:

ImGuiKey Enum

Keyboard Modifiers

On macOS, Dear ImGui swaps Cmd(Super) and Ctrl keys at the time of io.AddKeyEvent() call.

Key Data Structure

Access via:
MUST use key - ImGuiKey_NamedKey_BEGIN as index when accessing KeysData[].

Common Patterns

Check Multiple Keys

Smooth Movement with Keys

Key Repeat for UI Navigation

See Also

  • Mouse - Mouse input functions
  • Shortcuts - Keyboard shortcuts and input routing
  • Input - General input and ImGuiIO functions