Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move mouse cursor with node.js [closed]

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

like image 366
Nikolay Ayrapetov Avatar asked Mar 27 '14 17:03

Nikolay Ayrapetov


People also ask

How do I move cursor in node JS?

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.

Can you move mouse with JS?

You can't move the mouse pointer using javascript, and thus for obvious security reasons. The best way to achieve this effect would be to actually place the control under the mouse pointer.

Can you make a macro that moves your mouse?

Macro Recorder combines the sampled coordinates of a mouse movements into a single macro action. Such single mouse action can be edited, deleted, rearranged easily. The duration of the mouse movement is a single parameter.

How do I change the cursor position?

To move the cursor position with the mouse, simply click the destination point. Alternatively, you can use the following shortcut keys. CTRL+ RIGHT Move one word to the right. CTRL+ LEFT Move one word to the left.

How to move the mouse pointer to a specific position with JavaScript?

To move the mouse pointer to a specific position with JavaScript, we can call requestPointerLock in the element. to get the canvas element with getElementById. Then we call canvas.requestPointerLock to request permission to lock the mouse pointer in place.

How do I change the mouse pointer of a specific element?

There are two ways to change the mouse pointer using the query selector or accessing the specific element through tags. The getElementsByTagName () is JavaScript’s built-in document method and returns the NodeList objects/element whose tag matches the specified tag name. Active HTML collections are returned, including the root node in the search.

Is there a way to move the mouse on Windows?

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:

How do I get the current position of the mouse?

Getting the current position of the mouse getMousePos is a sort of help function which returns the xPosition and yPositiona of passed element into the function. lerp is also a help function that accepts 3 parameters (xPoint, yPoint, and amount).


1 Answers

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!

like image 121
Jason Stallings Avatar answered Sep 18 '22 14:09

Jason Stallings