Node js捕获键盘按下和鼠标移动(不在Web浏览器上) [英] Node js capture keyboard press and mouse movement (not on Web Browser)

查看:588
本文介绍了Node js捕获键盘按下和鼠标移动(不在Web浏览器上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用node js编写一个程序,该程序将捕获按键和鼠标的移动.不在网络浏览器上.这是我的个人项目的一种键盘记录程序.我尝试了robotjs,但是它需要很多依赖才能运行.有没有简单的方法可以做到这一点. 预先感谢

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

推荐答案

好像需要全局键挂钩.
尝试使用 iohook 模块

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();

它是跨平台本机模块,可在Windows,Linux,MacOS上运行

It is cross platform native module, works on Windows, Linux, MacOS

这篇关于Node js捕获键盘按下和鼠标移动(不在Web浏览器上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆