2

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...

Malki
  • 2,335
  • 8
  • 31
  • 61
  • found this question, seems relevant - http://stackoverflow.com/questions/22695122/move-mouse-cursor-with-node-js – Malki Jul 01 '15 at 06:10

1 Answers1

5

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();
Jason Stallings
  • 1,443
  • 20
  • 17