key-convert
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

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 pressed output
A a
A A
^ A ctrl A
up
^ home ctrl home
F2 f2
Esc esc
F9 alt 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

Package Sidebar

Install

npm i key-convert

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

16.4 kB

Total Files

9

Last publish

Collaborators

  • crindzebra