A simple utility for getting key info for a given Linux key code (as emitted by
/dev/input/eventX). Published on npm as linux-key-info.
Archived — this project is no longer maintained, but the npm package remains published and usable.
npm i --save linux-key-infoconst { keyCodeInfo, listAllKnownKeys } = require('linux-key-info');
console.log(keyCodeInfo(30).name); // 'A'
console.log(keyCodeInfo(1).name); // 'ESC'
console.log(listAllKnownKeys()); // all ~145 known keysPairs well with the input-event package for
reading raw keyboard events on Linux:
const InputEvent = require('input-event');
const { keyCodeInfo } = require('linux-key-info');
const input = new InputEvent('/dev/input/event0');
const keyboard = new InputEvent.Keyboard(input);
keyboard.on('keypress', (event) => {
const info = keyCodeInfo(event.code);
console.log(`Key pressed: code=${event.code}, name="${info.name}", char="${info.char}"`);
});Plain Node.js (CommonJS), no runtime dependencies. Built with webpack 4; tested with mocha/chai.
package.json on this branch is at 1.0.1; npm's published latest is 1.0.2 (a version-only
bump made from a tag that was never merged back to master). The code is identical between the
two — cosmetic only.
MIT