用node.js移动鼠标光标

是否有任何方式或模块移动光标和模拟鼠标点击windows7 / 8与node.js?

我发现这个库https://www.npmjs.org/package/win_mouse,但似乎不起作用

我一直在为这个RobotJS开发一个模块。

示例代码:

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(); 

这仍然是一个正在进行的工作,但它会做你想做的!

我之前已经尝试过win_mouse包,但它对我也不起作用,认为它需要一个旧版本的node.js。

一种解决scheme是使用ffi包,它允许你dynamic加载和调用本地库。 要在Windows上移动鼠标,您需要像这样调用user32.dllSetCursorPos函数:

 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, eg, "GetCursorPos" }); var result = user32.SetCursorPos(10, 10); console.log(result); 

另一个解决scheme是编写一个包装SetCursorPos函数的本地节点插件 ,但是它更复杂。