Overview
The shortcut system allows multiple widgets to register interest in a shortcut, but only one owner gets it based on focus routing. This makes shortcuts work correctly in complex hierarchies.Key Concepts
The general idea:- Several callers may register interest in a shortcut
- Only one owner gets it based on focus routing
- The system is order independent
Shortcut Function
Shortcut
ImGuiKeyChord
Key chord (e.g.,
ImGuiMod_Ctrl | ImGuiKey_S)ImGuiInputFlags
default:"0"
Input flags for routing and repeat behavior
bool
True if shortcut was pressed and routed to this code
SetNextItemShortcut
ImGuiKeyChord
Key chord for the shortcut
ImGuiInputFlags
default:"0"
Input flags
Key Chords
A key chord is a key optionally combined with modifiers:Input Flags
Repeat Flag
Routing Policies
Default policy isImGuiInputFlags_RouteFocused. Can select only 1 policy:
ImGuiInputFlags
Route to active item only.
ImGuiInputFlags
Route to windows in the focus stack (DEFAULT). Deep-most focused window takes inputs.
ImGuiInputFlags
Global route (unless a focused window or active item registered the route).
ImGuiInputFlags
Do not register route, poll keys directly.
Routing Options
Tooltip Flag
Routing Priority
Routing policies are resolved in this order:- RouteGlobal + OverActive
- RouteActive or RouteFocused (if owner is active item)
- RouteGlobal + OverFocused
- RouteFocused (if in focused window stack)
- RouteGlobal
Key Ownership
SetItemKeyOwner
ImGuiKey
Key to claim ownership of
Difference: IsKeyChordPressed vs Shortcut
IsKeyChordPressed
- Compares mods and calls
IsKeyPressed() - No side-effects
- No routing
Shortcut
- Submits a route
- Routes are resolved
- Calls
IsKeyChordPressed()if routed - Has side-effects (can prevent another call from getting the route)
Common Shortcut Patterns
Standard Editor Shortcuts
Application-Wide Shortcuts
Context-Sensitive Shortcuts
Debugging
Platform Considerations
On macOS, Dear ImGui automatically swaps Cmd(Super) and Ctrl keys:
ImGuiMod_Ctrl= Cmd on macOS, Ctrl on other platformsImGuiMod_Super= Ctrl on macOS, Windows/Super on other platforms