keycuts is a modern Javascript library for handling keyboard shortcuts. It supports listening for key combinations, key sequences and a mix of both. keycuts has no external dependencies and a small footprint (~8kb, gzipped ~3kb).
Installation
$ npm install keycuts --save# or $ yarn add keycuts
Alternatively you can download the distributed library and link it into your webpage.
Usage
// Import using ES6 modules syntax// or when linked directly in the webpageconst Keys = keycutsKeys // Create a new object (without any parameter it is directly attached// to the window object)const keys = // Trigger a provided callback when a specific key combination is pressedkeys // You can also provide the shortcut using a string syntaxkeys // Sequences of key or key combinations are supported tookey // And the appropriate string syntaxkey // Watch every keydown or keyup event and have access// to the current key sequencekey
But keycuts can do more! The full documentation, API reference and a demo can be found on the keycuts homepage.
Development
For development fetch the code from Github and install the dependencies.
$ git clone https://github.com/medihack/keycuts.git$ cd keycuts$ npm install # or yarn install
keycuts uses Webpack to transpile the source code (src/
) into a minified and non-minified bundle in the dist/
folder.
$ npm run build
You can easily start a development server with the demo which automatically recompiles the code and refreshes the page when the source files are modified (files under dist/ stay untouched).
// Start a development server on port 8000$ npm run start // Just visit localhost:8000 in your browser
Run the test suite (using Jest) once or automatically when a source or test file was changed.
// Run all tests once$ npm run test// or contiously$ npm run test:watch
More scripts to manage the library can be found in the scripts section in the (./package.json) file.
To contribute, please fork, add your patch, write tests for it and submit a pull request.
Contributions
Logo by Torsten Kühr (werkst.de)