macotron.mouse
Read the pointer position and the button state, and move the pointer to a new spot.
// Nudge the pointer 100 points to the right.
const { x, y } = macotron.mouse.location();
macotron.mouse.warp(x + 100, y);
Coordinates
location() and warp() use Cocoa screen points. The origin is the bottom-left corner of the main display, and y grows upward. Window frames, accessibility frames, and event coordinates use the top-left corner instead, with y growing downward. To convert, subtract y from the height of the main display.
Pointer
location(): { x: number, y: number }
The current pointer position in Cocoa screen points. It needs no permission.
warp(x: number, y: number): boolean
warp(point: { x: number, y: number }): boolean
Moves the pointer to the point, in Cocoa screen points. It does not click, and apps get no mouse-moved event. Returns false only when the arguments are missing.
buttons(): { left: boolean, right: boolean, center: boolean }
Which mouse buttons are held right now. center is the middle button.
See also
- macotron.event to click, scroll, or watch mouse events.
- macotron.window for window frames.