2016-01-24 53 views
3

我正在尝试使用节点js制作一个程序,该程序将捕获按键和鼠标移动。不在Web浏览器上。这是我个人项目中的一种键盘记录器类型。我尝试了robotjs,但它需要很多依赖才能运行。有没有简单的方法来做到这一点。 感谢提前节点js捕获键盘按键和鼠标移动(不在Web浏览器上)

+0

你尝试过:https://www.npmjs.com/package/keylogger – AlwaysNull

+1

是,这个包完全是垃圾。它只存储您在终端上输入的内容。没有别的 –

+0

你到目前为止尝试过什么?这使人们很容易给你一个答案。 – AlwaysNull

回答

0

您是否尝试过使用按键模块?从回购https://github.com/TooTallNate/keypress

实例为KEY:从回购

var keypress = require('keypress'); 
// use decoration to enable stdin to start sending ya events 
keypress(process.stdin); 
// listen for the "keypress" event 
process.stdin.on('keypress', function (ch, key) { 
    console.log('got "keypress"', key); 
    if (key && key.ctrl && key.name == 'c') { 
     process.stdin.pause(); 
    } 
}); 

process.stdin.setRawMode(true); 
process.stdin.resume(); 

实例为鼠标: VAR按键=要求( '按键');

// make `process.stdin` begin emitting "mousepress" (and "keypress") events 
keypress(process.stdin); 

// you must enable the mouse events before they will begin firing 
keypress.enableMouse(process.stdout); 

process.stdin.on('mousepress', function (info) { 
    console.log('got "mousepress" event at %d x %d', info.x, info.y); 
}); 

process.on('exit', function() { 
    // disable mouse on exit, so that the state 
    // is back to normal for the terminal 
    keypress.disableMouse(process.stdout); 
}); 
+1

是的我试过了,但这不是我正在寻找的东西,我只是想要类似于真正的密钥记录器实际上追踪我的按键/释放无论我键入和点击 –

1

看起来像你需要全局钥匙钩。
尝试使用iohook模块

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

ioHook.on("mousemove", event => { 
    console.log(event); 
    // result: {type: 'mousemove',x: 700,y: 400} 
}); 
ioHook.on("keypress", event => { 
    console.log(event); 
    // result: {keychar: 'f', keycode: 19, rawcode: 15, type: 'keypress'} 
}); 
//Register and stark hook 
ioHook.start(); 

它是跨平台的本机模块,适用于Windows,Linux和MacOS的