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
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
Share Improve this question edited Apr 10, 2019 at 14:35 Prappo asked Jan 24, 2016 at 10:35 PrappoPrappo 8921 gold badge9 silver badges23 bronze badges 6- have you tried: npmjs.com/package/keylogger – AlwaysNull Commented Jan 24, 2016 at 15:21
- 5 Yes , this package totally garbage . It only store what you typed on terminal . nothing else – Prappo Commented Jan 24, 2016 at 19:51
- What have you tried so far? This makes it easy for people to give you an answer. – AlwaysNull Commented Jan 24, 2016 at 19:55
- 1 I have been googling to find any package for node to capture keyboard and mouse but nothing found . only one package meet with my requirement and that is robotjs but it's need too many dependency and not possible for me to implement for my project :( – Prappo Commented Jan 25, 2016 at 14:00
- 1 I am on the same boat. While Robotjs allows you to control user's mouse & keyboard, I need a tool which would help me to record user's movement – Kunok Commented May 19, 2018 at 2:07
2 Answers
Reset to default 13Looks 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);
});