0.0.1 • Published 5 years ago

key-convert v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

key-convert

Convert keycode sequence to key string

Get Started

Install from npm.

npm install key-convert

Example

import convert from 'key-convert';
process.stdin.setRawMode(true);
process.stdin.on('data',(chunk)=>{
    let keyInput = convert(dat);
    if(keyInput.type=='printable'){
        process.stdout.write(keyInput.sequence+'\n');
    }else{
        for(let k of keyInput.keys){
            if(typeof(k)=='string'){
                process.stdout.write(k+' ');
            }else{
                process.stdout.write(Keys[k]+' ');
            }
        }
        process.stdout.write('\n');
    }
    if(dat.readInt8(0)==4)process.exit();
});
key pressedoutput
Aa
AA
^ Actrl A
up
^ homectrl home
F2f2
Escesc
F9alt f9

Usage

convert

convert(chunk:Buffer):KeyInput

converting terminal-input sequences to key names.

KeyInput

type KeyInput = ({
    type:'printable';
    sequence:string;
}|{
    type:'non-printable';
    keys:(Keys|string)[];
});

Keys

enum Keys