Skip to content

ryuever/key-emitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

key emitter

minor snippet to react to key stroke

Arrow key

For every key down or key up operation, it will trigger a change event. Enter key will trigger commit event;

For change handler, it will receive a next index value;

for commit handler, it will receive a current triggered index value.

options

max

It's requried, which will indicate the max index value on key down or key up.

usage

import { ArrowKeyHandler } from 'key-emitter';

this.arrowHandler = new ArrowKeyHandler({
  max: max,
});

this.arrowHandler.on('change', ({ index }) => {
  // ...
})

this.arrowHandler.on('commit', ({ index }) => {
  // ...
})

About

minor snippet to react to key stroke

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published