I'm trying to make a program using node js that will capture key press and mouse movement . Not on web browser . It's one kind of keylogger type for my personal project . I tried robotjs but it's need many dependency to run . Is there any simple way to do that . Thanks in advance
Looks like you need global key hook.
Try to use iohook module
'use strict';
const ioHook = require('iohook');
ioHook.on("mousemove", event => {
console.log(event);
// result: {type: 'mousemove',x: 700,y: 400}
});
ioHook.on("keydown", event => {
console.log(event);
// result: {keychar: 'f', keycode: 19, rawcode: 15, type: 'keypress'}
});
//Register and stark hook
ioHook.start();
It is cross platform native module, works on Windows, Linux, MacOS
Have you tried using the keypress module? https://github.com/TooTallNate/keypress
Examples from the repo for 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();
Examples from the repo for Mouse: var keypress = require('keypress');
// 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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With