Lpc_dark
Lpc_dark

Reputation: 2952

Mouse movement in Nodejs

I was wondering if in nodejs we can get the mouse position. It's such a simple quick question but i just can't find a yes or no answer.

So the simple question is can i get mouse position using native node?

Also it would be good to not think of node as a server side language for this question.

Node can be run any where. Hence node webkit. This is a webkit application but it's node running in the back end.

I just want to track mouse. Problem is if the mouse goes off the page it's now untrackable. but i want to track it outside the window as well.

Upvotes: 1

Views: 7561

Answers (3)

Jason Stallings
Jason Stallings

Reputation: 1473

I've been working on a module for getting the mouse position, 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();

Upvotes: 5

Joche
Joche

Reputation: 346

client side:

document.getElementsByTagName("BODY")[0].onmousemove = function(eventData) {
    iosocket.send("mousemove", eventData);
}

sever side:

socket.on('message', function(action,p2) {
    if ("mousemove" == action) {
       /* YOUR CODE GOES HERE */
    }
})

Upvotes: -2

bribeiro
bribeiro

Reputation: 727

Node runs on the server side, the mouse is on the client side. What you can do is use sockets or something like that and send the mouse position to the server.

Upvotes: -3

Related Questions