Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node js capture keyboard press and mouse movement (not on Web Browser)

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

like image 212
Prappo Avatar asked Jan 24 '16 10:01

Prappo


2 Answers

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

like image 58
Aloyan Dmitry Avatar answered Nov 02 '22 21:11

Aloyan Dmitry


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);
});
like image 3
Stacey Mulcahy Avatar answered Nov 02 '22 21:11

Stacey Mulcahy