Mouse Control
nut.js allows simulation of mouse input by moving the cursor, clicking mouse buttons or performing dragging gestures.
#
ConfigurationThe nut.js mouse comes with a config object which allows configuration of its behaviour.
autoDelayMs
#
mouse.config.autoDelayMs
configures the delay between mouse clicks and / or scrolls.
mouseSpeed
#
mouse.config.mouseSpeed
configures mouse movement speed in pixels per second.
setPosition
#
setPosition
takes a Point and moves the mouse cursor to this position instantly.
getPosition
#
getPosition
returns a Promise which resolves to the current cursor Point
move
#
move
is the general purpose method for mouse movement in nut.js.
It receives a path given either as Point[] or Promise<Point[]> and a movement function of type (amountOfSteps: number, speedInPixelsPerSecond: number): number[]
, returns a list of durations in nanoseconds.
mouse.move
will follow this path in timesteps provided by the movement function.
This way it's possible to fully customize mouse movment behaviour by implementing own functions for path calculation and / or movment timing.
straightTo
#
straightTo
is a movement function which takes a target Point and calculates a path of Point[] leading from the current mouse position to the desired target.
centerOf
#
centerOf
is a helper function which takes a Region and returns the center Point of that region.
centerOf
is a great fit for straightTo
as it allows us to move to the center of a Region returned by e.g. screen.find
.
randomPointIn
#
randomPointIn
is another helper function which takes a Region and returns a random Point within that region.
randomPointIn
is a great fit for straightTo
as it allows us to move to the center of a Region returned by e.g. screen.find
.
left
#
left
is a relative movement function which returns a path moving x
pixels to the left of your current mouse position.
right
#
right
is a relative movement function which returns a path moving x
pixels to the right of your current mouse position.
up
#
up
is a relative movement function which returns a path moving x
pixels up from your current mouse position.
down
#
down
is a relative movement function which returns a path moving x
pixels down from your current mouse position.
leftClick
#
leftClick
performs a click with the left mouse button at the current cursor position.
rightClick
#
rightClick
performs a click with the right mouse button at the current cursor position.
scrollDown
#
scrollDown
scrolls x
"ticks" downwards. Absolute scroll width depends on your system.
scrollUp
#
scrollUp
scrolls x
"ticks" upwards. Absolute scroll width depends on your system.
scrollLeft
#
scrollLeft
scrolls x
"ticks" to the left. Absolute scroll width depends on your system.
scrollRight
#
scrollRight
scrolls x
"ticks" to the right. Absolute scroll width depends on your system.
drag
#
Similar to move
, drag
moves the mouse cursor along a given path.
While moving, it presses and holds the left mouse button, performing a drag gesture.
pressButton
#
pressButton
presses and holds a given mouse button.
releaseButton
#
releaseButton
releases a given mouse button.