Node.JS trigger click event to OS

1.5k views Asked by At

I'm looking for a way to trigger a click event to the OS from a NodeJS application. All I need is to have control over x/y and mouse button.

Is there anything that does that? I've searched for existing packages but didn't find any...

1

There are 1 answers

0
Jason Stallings On

RobotJS does exactly what you want!

http://github.com/octalmage/robotjs

Try this code:

//Get the mouse position, move it, then click.

var robot = require("robotjs");

//Get the mouse position, returns an object with x and y. 
var mouse = robot.getMousePos();
console.log("Mouse is at x:" + mouse.x + " y:" + mouse.y);

//Move the mouse down by 100 pixels.
robot.moveMouse(mouse.x, mouse.y + 100);

//Left click!
robot.mouseClick();