Skip to main content

Mouse Button State

IsMouseDown

Check if mouse button is being held.
ImGuiMouseButton
Mouse button (0=left, 1=right, 2=middle)
bool
True if button is currently down
Example:

IsMouseClicked

Check if mouse button was clicked (went from !Down to Down). Same as GetMouseClickedCount() == 1.
ImGuiMouseButton
Mouse button to check
bool
default:"false"
If true, returns true on repeat clicks
bool
True if button was just clicked
Example:

IsMouseReleased

Check if mouse button was released (went from Down to !Down).
ImGuiMouseButton
Mouse button to check
bool
True if button was just released

IsMouseDoubleClicked

Check if mouse button was double-clicked. Same as GetMouseClickedCount() == 2.
ImGuiMouseButton
Mouse button to check
bool
True if button was double-clicked
A double-click will also report IsMouseClicked() == true.
Example:

GetMouseClickedCount

Return the number of successive mouse clicks at the time where a click happened.
ImGuiMouseButton
Mouse button to check
int
Number of clicks (0=not clicked, 1=single click, 2=double click, 3=triple click, etc.)
Example:

Mouse Position

GetMousePos

Get mouse position. Shortcut to ImGui::GetIO().MousePos.
ImVec2
Mouse position in screen coordinates
Example:

GetMousePosOnOpeningCurrentPopup

Retrieve mouse position at the time of opening popup we have BeginPopup() into. Useful to avoid user backing that value themselves.
ImVec2
Mouse position when popup was opened

IsMousePosValid

Check if mouse position is valid. By convention, we use (-FLT_MAX, -FLT_MAX) to denote no mouse available.
const ImVec2*
default:"NULL"
Mouse position to check (NULL = use current mouse position)
bool
True if position is valid

Mouse Dragging

IsMouseDragging

Check if mouse is dragging. Uses io.MouseDraggingThreshold if lock_threshold < 0.0f.
ImGuiMouseButton
Mouse button to check
float
default:"-1.0f"
Distance threshold before considering dragging. Use -1.0f for default threshold.
bool
True if mouse is dragging
Example:

GetMouseDragDelta

Return the delta from the initial clicking position while the mouse button is pressed or was just released. This is locked and returns 0.0f until the mouse moves past a distance threshold at least once.
ImGuiMouseButton
default:"0"
Mouse button to check
float
default:"-1.0f"
Distance threshold. Use -1.0f for io.MouseDraggingThreshold.
ImVec2
Drag delta in pixels
Example:

ResetMouseDragDelta

Reset drag delta for a mouse button.
ImGuiMouseButton
default:"0"
Mouse button to reset

Mouse Hovering

IsMouseHoveringRect

Check if mouse is hovering given bounding rect in screen space. Clipped by current clipping settings, but disregarding of other consideration of focus/window ordering/popup-block.
const ImVec2&
Top-left corner of rectangle
const ImVec2&
Bottom-right corner of rectangle
bool
default:"true"
Whether to respect current clipping rectangle
bool
True if mouse is within rectangle
Example:

Mouse Cursor

GetMouseCursor

Get desired mouse cursor shape. Important: reset in ImGui::NewFrame(), updated during the frame. Valid before Render().
ImGuiMouseCursor
Cursor type

SetMouseCursor

Set desired mouse cursor shape.
ImGuiMouseCursor
Cursor type to set
Example:

Mouse Cursor Types

Mouse Button Enum

These values are guaranteed to be stable. You can use 0/1 directly.

Mouse Capture

SetNextFrameWantCaptureMouse

Override io.WantCaptureMouse flag next frame. Equivalent to setting io.WantCaptureMouse after the next NewFrame() call.
bool
Whether to capture mouse

Common Patterns

Custom Drag Widget

Click Detection with Double-Click

Custom Context Menu

See Also

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