Shortway
Tiny to library to handle keyboard shortcuts in the browser. Feel free to use it with any kind of keyboard events and attach them to any element that you want.
Install
This project uses node and npm. Go check them out if you don't have them locally installed.
$ npm install --dev shortway
Then with a module bundler like rollup or webpack, use as you would anything else:
// using ES6 modules // using CommonJS modulesvar shortway =
The UMD build is also available on unpkg:
You can find the library on window.shortway
.
Usage
const callback = {console} const spaceShortcut = document const customShortcut = document
Supported Keys
Shortway current supports ctrl, alt and shift along with the following shortcuts:
- backspace
- tab
- enter
- esc
- space
- pageup
- pagedown
- end
- home
- 0-9
- a-z
- f1-f12
- Arrows: left, top, right, down
- insert
- delete
- slash: /
API
shortway(command, callback)
command
A sequence of keys to be watched.
Examples:
callback
A callback to be executed when a sequence of keys is predded.
Examples:
const callback = { console}
Contributing
See the contributing file.