Capturing global keyboard events on Linux using NodeJS

I have a headless ARM Debian machine in which I run Node. The device has hard buttons that are displayed on ordinary keyboard events using gpio-keys.

My goal is to capture global events both from hard buttons and from any connected keyboards in Node. I need a solution that can capture keydown / keyup events regardless of the terminal in which it is running (it will be running through an SSH session). It does not have to be cross-platform, if it runs on ARM Debian, I will accept it.

I imagine something that is read directly from any attributes sysfs, but this is not a requirement.

Can someone help me with this? I got stuck for a while.

+4
source share
1 answer

One of the device files /dev/input/event*will be a gpio-keys device. You can figure out which one has several ways; one simple is to view the contents of the uevent file for the device, for example. /sys/class/input/event0/device/uevent. It will contain a number of useful key-value properties.

Once you figure out which device you want, you can open and read it. It will return stream struct input_events as defined in <linux/input.h>. These events will correspond to clicks and releases for each of your buttons.

, , , node -keyboard: https://github.com/Bornholm/node-keyboard

+1

Source: https://habr.com/ru/post/1547506/


All Articles