Skip to content

Latest commit

 

History

History
61 lines (43 loc) · 2.18 KB

README.md

File metadata and controls

61 lines (43 loc) · 2.18 KB

npm Github file size GitHub tag npm Bintray GitHub issues Maintainability Depfu

node-linux-key-info

A simple utility for getting key info for a given linux key code.

Installation:

# using npm
npm i --save linux-key-info

# or yarn
yarn add linux-key-info

Usage:

// get info for a given key code
const keyCodeInfo = require('linux-key-info').keyCodeInfo;

console.log(keyCodeInfo(30).name); // 'A'
console.log(keyCodeInfo(30).char); // 'A'

console.log(keyCodeInfo(1).name); // 'ESC'
console.log(keyCodeInfo(1).char); // ''

// list all known keys
const listAllKnownKeys = require('linux-key-info').listAllKnownKeys;

console.log('All known keys:',listAllKnownKeys());

Example usage with 'input-event' package

$ npm i input-event linux-key-info --save
const InputEvent = require('input-event');
const keyCodeInfo = require('linux-key-info').keyCodeInfo;

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}"`);
});