Now that we're all set up it's time to get things moving!
working directory, let's create a new file,
Open it in your favourite editor and add the following lines to get started:
mouse gives you control over your, well, mouse, so let's play around with it a bit!
Attention: nut.js is fully async, so in most examples you will see something like the above snippet, which is an async IIFE used as a workaround to use
await at the top-level.
nut.js provides a declarative API, so instead of explicitly stating where we want our cursor to be, we can use the MovementApi functions to move our cursor relative to our current position.
When executed via
node index.js you'll see that your cursor moves along a square and ends up at its initial position.
Moving our cursor in up, down, left or right direction is a good start, but we're not sitting in front of an Etch A Sketch. Let's see how we can target specific points on our screen.
straightTo is another
MovementApi function which takes a target Point and computes a straight line towards it, starting at our current cursor position.
In case you want to configure mouse movement speed to go faster / slower, every instance exposed by nut.js provides a
The mouse config object allows you to configure movement speed measured in pixels per second.
Sometimes we don't want to move along a path to reach a certain point.