funkey
Funkey is a self-currying keyboard event handler. You provide the keyboard event, http://bukk.it/hahano.pngfunkey
provides the fun.
Download
Using npm:
$ npm i --save funkey
Basic Usage
document
Arguments
keyboardEvent
- A keyboard event to handle.keyName
- The keyboard key combination to match.callback
- A callback to invoke with event ifkeyName
matches event.
The KeyName
The keyName
is made up of the modifiers and the key itself. The available modifiers are ctrl
, alt
, shift
and super
. The available key names are a single character, or a named key, which may be one of:
f1-12, tab, backspace, enter, shift, pause, capslock, escape, space, pageup, pagedown, end, home, left, up, right, down, insert, delete, select, multiply, add, subtract, decimal, divide, numlock, scrolllock, numpad0-9
Currying
Funkey is self-currying and the keyboard event argument can be given in any position when invoking funkey
. This makes funkey pretty flexible. Here are some examples:
document
var onEnterDoStuff = ;var onEscapeDoOtherStuff = ; document;
var console;var onShiftDown = ;document;
The callback context is also correctly maintained:
const controller = {} onKey: ; document;
Roadmap
- Improved docs
- Impliment newer
KeyboardEvent.key
property parsing.
References
Inspiration and sources.
Contributing
Don't be shy! Submit issues (or better yet PRs) if you see anything that could be better. If you're submitting code that contains patches or features please try to include unit tests. Thanks!
Author
Piet van Zoen hi@pietvanzoen.com