MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / animatedMove

Function animatedMove

src/utils/computerUse/executor.ts:274–312  ·  view source on GitHub ↗

* Port of Cowork's `animateMouseMovement` + `animatedMove`. Ease-out-cubic at * 60fps; distance-proportional duration at 2000 px/sec, capped at 0.5s. When * the sub-gate is off (or distance < ~2 frames), falls through to * `moveAndSettle`. Called only from `drag` for the press→to motion — target

(
  input: Input,
  targetX: number,
  targetY: number,
  mouseAnimationEnabled: boolean,
)

Source from the content-addressed store, hash-verified

272 * intermediate positions (scrollbars, window resizes).
273 */
274async function animatedMove(
275 input: Input,
276 targetX: number,
277 targetY: number,
278 mouseAnimationEnabled: boolean,
279): Promise<void> {
280 if (!mouseAnimationEnabled) {
281 await moveAndSettle(input, targetX, targetY)
282 return
283 }
284 const start = await input.mouseLocation()
285 const deltaX = targetX - start.x
286 const deltaY = targetY - start.y
287 const distance = Math.hypot(deltaX, deltaY)
288 if (distance < 1) return
289 const durationSec = Math.min(distance / 2000, 0.5)
290 if (durationSec < 0.03) {
291 await moveAndSettle(input, targetX, targetY)
292 return
293 }
294 const frameRate = 60
295 const frameIntervalMs = 1000 / frameRate
296 const totalFrames = Math.floor(durationSec * frameRate)
297 for (let frame = 1; frame <= totalFrames; frame++) {
298 const t = frame / totalFrames
299 const eased = 1 - (1 - t) ** 3
300 await input.moveMouse(
301 Math.round(start.x + deltaX * eased),
302 Math.round(start.y + deltaY * eased),
303 false,
304 )
305 if (frame < totalFrames) {
306 await sleep(frameIntervalMs)
307 }
308 }
309 // Last frame has no trailing sleep — same HID round-trip before the
310 // caller's mouseButton reads NSEvent.mouseLocation.
311 await sleep(MOVE_SETTLE_MS)
312}
313
314// ── Factory ───────────────────────────────────────────────────────────────
315

Callers 1

dragFunction · 0.85

Calls 4

moveAndSettleFunction · 0.85
mouseLocationMethod · 0.65
moveMouseMethod · 0.65
sleepFunction · 0.50

Tested by

no test coverage detected