11

I've been looking for a native nodejs module that supports mouse and keyboard listening and execution

i found this.. https://npmjs.org/package/mouse but the source code looks like it only supports the browsers.

4

4 回答 4

12

我一直在研究用于发送鼠标和键盘事件的模块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();

然后为了听我使用 nw.js:

https://github.com/nwjs/nw.js/wiki/Shortcut

于 2015-01-29T18:20:30.990 回答
4

您可以使用该模块包装Robot ClassJava 提供的跨平台解决方案。node-java

工作示例:

var java = require('java');

var Robot = java.import('java.awt.Robot');
var robot = new Robot();

robot.mouseMoveSync(0, 0);
于 2014-01-12T22:00:41.157 回答
4

试试iohook模块。
它支持Windows/Linux/MacOS

'use strict';
const ioHook = require('iohook');

ioHook.on("mousemove", event => {
   console.log(event);
   /* You get object like this
   {
      type: 'mousemove',
      x: 700,
      y: 400
    }
   */
});
// For keyboard hook
ioHook.on("keydown", event => { .... });
ioHook.on("keyup", event => { .... });

//Register and start hook 
ioHook.start();
于 2017-04-20T12:39:08.323 回答
1

看看https://github.com/Loknar/node-macmouse

$ npm 安装 macmouse

例子.js

var mouse = require('macmouse');

mouse.init();

var ptX = 800;
var ptY = 600;

var doThings = function() {
    mouse.Place(ptX, ptY);
    setTimeout(pressAndHold, 250);
}

var pressAndHold = function() {
    mouse.LeftButtonPress();
    setTimeout(doDragStuff, 250);
}

var doDragStuff = function() {
    ptX += 2;
    ptY += 2;
    mouse.DragPlace(ptX, ptY);
    setTimeout(doDragStuff, 250);
}

doThings();

mouse.quit();
于 2015-02-06T18:44:40.607 回答