System keystroke detection? (node.js?)

Is it possible to detect a keystroke even if my node application is not in focus?

In those days, there was this tool for warcraft that would quickly move the mouse to a specific position and trigger a click when a key is pressed. This tool can still work on windows, but I planned to create something similar for Mac (or with node.js even on the system system), and not for Warcraft.

I searched a lot and found several tools for moving the mouse and sending keys like nodemacmouse or robojs , but I could not find anything to detect keyboard input on the system keyboard (which is crucial since movements should only occur when a key is pressed). This is similar in cocoa , but the node solution would be flawless. Is it possible? How? Thank.

+4
source share
1 answer

It took me a long time to find a package that will receive keyboard events, but this package does the work for me on Ubuntu and OpenWRT:

https://www.npmjs.com/package/input-event

From the documentation:

var InputEvent = require('input-event');

var input = new InputEvent('/dev/input/event0');

var keyboard = new InputEvent.Keyboard(input);

keyboard.on('keyup'   , console.log);
keyboard.on('keydown' , console.log);
keyboard.on('keypress', console.log);
0
source

All Articles