Browse the docs

Drag mouse

Presses the mouse button, drags the pointer to another place, and releases it.

Drag the mouse from from to to

Keyboard Maestro: MouseMoveAndClick

Details #

Presses the button at the start point, moves the pointer in a smooth line, and releases it at the end. The whole drag takes a little over a tenth of a second.

The start is from. Without it, the drag starts from where the pointer is now. The end is either to (a position on screen) or by (a distance from the start). One of them is required.

Positions are screen points from the top left.

The output holds the start and end as fromX, fromY, toX and toY.

Parameters #

ParameterTypeRequiredValuesWhat it does
buttonone ofleft right middleleft (default) or right.
byrecorddx dyDistance { "dx": 300, "dy": 0 } from the start, as an alternative to to.
fromrecordx yStart position { "x": 100, "y": 200 }. Defaults to the current pointer.
modifierslist ofcmd ctrl opt shift fn hyperKeys held during the drag, from cmd, ctrl, opt, shift, fn, hyper.
torecordx yEnd position { "x": 400, "y": 200 }.

Every step also accepts label, onFailure, timeout and dryRunSafe.

Examples #

Drag 200 points to the right from the current pointer (really drags)
Do
  1. Drag by (200, 0)
Open in Switchboard to try it
Option-drag between two screen points to copy an item (really drags)
Do
  1. Drag from (300, 300) to (700, 300)
Open in Switchboard to try it

Gotchas #

  • Fixed coordinates break when windows move. To start the drag on an element, use Click with count 0 and a locator to move the pointer there, then drag by a distance.

  • Some apps need a slower drag than this one. If a drag-and-drop does nothing, try it by hand first to be sure the app supports it.

  • With no to and no by, the step fails.

  • Switchboard needs the Accessibility permission.

See also #

Click, Move pointer by, Scroll