Is there is any way or module to move cursor and simulate mouse clicks in windows7/8 with node.js?
I found this library https://www.npmjs.org/package/win_mouse but seems like it doesn't work
Is there is any way or module to move cursor and simulate mouse clicks in windows7/8 with node.js?
I found this library https://www.npmjs.org/package/win_mouse but seems like it doesn't work
I've been working on a module for this, RobotJS.
Example code:
var robot = require("robotjs");
//Get the mouse position, retuns 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();
It's still a work in progress but it will do what you want!
I've previously tried the win_mouse
package, but it didn't work for me either, think it requires an older version of node.js.
One solution would be to use the ffi package, which allows you to dynamically load and call native libraries. To move the mouse on windows, you'd need to call the SetCursorPos
function from the user32.dll
like this:
var ffi = require("ffi");
var user32 = ffi.Library('user32', {
'SetCursorPos': [ 'long', ['long', 'long'] ]
// put other functions that you want to use from the library here, e.g., "GetCursorPos"
});
var result = user32.SetCursorPos(10, 10);
console.log(result);
Another solution would be to write a native node add-on that wraps around the SetCursorPos
function, but it is more complex.