uloop-simulate-mouse-ui
Task
Simulate mouse interaction on Unity PlayMode UI: $ARGUMENTS
Workflow
- Ensure Unity is in PlayMode (use
uloop control-play-mode --action Playif not) - Get UI element info:
uloop screenshot --capture-mode rendering --annotate-elements --elements-only - Use the
AnnotatedElementsarray to find the target element byNameorLabel(A=frontmost, B=next, ...). UseSimX/SimYdirectly as--x/--ycoordinates. - Execute the appropriate
uloop simulate-mouse-uicommand - Take a screenshot to verify the result:
uloop screenshot --capture-mode rendering --annotate-elements - Report what happened
Tool Reference
uloop simulate-mouse-ui --action <action> --x <x> --y <y> [options]
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
--action |
enum | Click |
Click, Drag, DragStart, DragMove, DragEnd, LongPress |
--x |
number | 0 |
Target X position in screen pixels (origin: top-left). For Drag action, this is the destination. |
--y |
number | 0 |
Target Y position in screen pixels (origin: top-left). For Drag action, this is the destination. |
--from-x |
number | 0 |
Start X position for Drag action. Drag starts here and moves to x,y. |
--from-y |
number | 0 |
Start Y position for Drag action. Drag starts here and moves to x,y. |
--drag-speed |
number | 2000 |
Drag speed in pixels per second (0 for instant). 2000 is fast (default), 200 is slow enough to watch. Applies to Drag, DragMove, and DragEnd actions. |
--duration |
number | 0.5 |
Hold duration in seconds for LongPress action. |
--button |
enum | Left |
Mouse button: Left, Right, Middle. |
Actions
| Action | Event Fired | Description |
|---|---|---|
Click |
PointerDown → PointerUp → PointerClick | Click at (x, y) with the selected --button |
LongPress |
PointerDown → (hold) → PointerUp | Press and hold at (x, y) for --duration seconds, then release. No PointerClick is fired. |
Drag |
BeginDrag → Drag×N → EndDrag | One-shot drag from (fromX, fromY) to (x, y) at the specified speed |
DragStart |
BeginDrag | Begin drag at (x, y) and hold |
DragMove |
Drag×N | Animate from current position to (x, y) at the specified speed |
DragEnd |
Drag×N → EndDrag | Animate to (x, y) at the specified speed, then release drag |
Split Drag Rules
DragStartmust be called beforeDragMoveorDragEndDragEndmust be called to release an active drag — failing to call it leaves drag state stuck- Calling
DragMoveorDragEndwithout an active drag returns an error
Global Options (all optional, mutually exclusive)
| Option | Description |
|---|---|
--project-path <path> |
Optional. Use only when the target Unity project is not the current directory. |
Coordinate System
- Origin is top-left (0, 0)
- All positions are in screen pixels
- Get coordinates from
AnnotatedElementsJSON (SimX/SimY) — do NOT look up GameObject positions - Clicking or long-pressing on empty space (no UI element) still succeeds with a message indicating no element was hit
- Dragging on empty space (no draggable UI element) returns
Success = false
Examples
# Click a button at screen position
uloop simulate-mouse-ui --action Click --x 400 --y 300
# Long-press a button for 3 seconds
uloop simulate-mouse-ui --action LongPress --x 400 --y 300 --duration 3.0
# One-shot drag (start to end in one call)
uloop simulate-mouse-ui --action Drag --from-x 400 --from-y 300 --x 600 --y 300
# Slow drag for visual inspection
uloop simulate-mouse-ui --action Drag --from-x 400 --from-y 300 --x 600 --y 300 --drag-speed 200
# Split drag with hold (for inspection between steps)
uloop simulate-mouse-ui --action DragStart --x 400 --y 300
uloop screenshot --window-name Game
uloop simulate-mouse-ui --action DragMove --x 500 --y 300
uloop simulate-mouse-ui --action DragEnd --x 600 --y 300
Prerequisites
- Unity must be in PlayMode
- Target scene must have an EventSystem GameObject
- UI elements must have a GraphicRaycaster on their Canvas
More from hatayama/unity-cli-loop
uloop-control-play-mode
Control Unity Editor play mode (play/stop/pause). Use when you need to: (1) Start play mode to test game behavior, (2) Stop play mode to return to edit mode, (3) Pause play mode for frame-by-frame inspection.
3uloop-run-tests
Execute Unity Test Runner and get detailed results. Use when you need to: (1) Run EditMode or PlayMode unit tests, (2) Verify code changes pass all tests, (3) Diagnose test failures with error messages and stack traces. Auto-saves NUnit XML results on failure.
2uloop-compile
Compile Unity project and report errors/warnings. Use when you need to: (1) Verify code compiles after C# file edits, (2) Check for compile errors before testing, (3) Force full recompilation with Domain Reload. Returns error and warning counts.
2uloop-screenshot
Capture screenshots of Unity Editor windows as PNG files. Use when you need to: (1) Screenshot Game View, Scene View, Console, Inspector, or other windows, (2) Capture current visual state for debugging or documentation, (3) Save editor window appearance as image files.
2uloop-launch
Launch Unity project with matching Editor version via uloop CLI. Use when you need to: (1) Open a Unity project with the correct Editor version, (2) Restart Unity to apply changes, (3) Switch build target when launching.
2uloop-get-logs
Retrieve logs from Unity Console with filtering and search. Use when you need to: (1) Check for errors or warnings after compilation or play mode, (2) Debug issues by searching log messages, (3) Investigate failures with stack traces. Supports filtering by log type, text search, and regex.
2