https://github.com/one-com/keystroke-handler
https://github.com/one-com/keystroke-handler
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/one-com/keystroke-handler
- Owner: One-com
- License: bsd-3-clause
- Created: 2019-09-13T08:15:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-25T12:45:48.000Z (over 5 years ago)
- Last Synced: 2025-02-05T07:49:09.664Z (4 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 9
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# KeystrokeHandler
This module provides support for binding keys to named areas
within applications.[](http://badge.fury.io/js/keystroke-handler)
[](https://travis-ci.org/One-com/keystroke-handler)This module is a small wrapper around
[mousetrap](https://github.com/ccampbell/mousetrap)
library that handles the named areas and corresponding keys.# Use
A key handler is created by instantiating it passing a
top-level target element to whcih it will bind events:```js
var KeystrokeHandler = require("keystroke-handler");var keyHandler = new KeystrokeHandler(document);
```From that point forward it is available to have keys
added to it. The key defnitions are identical to those
supported by mousetrap - see: https://craig.is/killing/mice#keys.## Global Keys
Keys can be registered for the the target element and all
its children as follows:```js
keyHandler.register("h", function() {
// ... call a function to show help
});
```## Domain keys
Keys can be added to `domains` to scope keys to a particular
area within an application.There can be registered on the fly:
```js
keyHandler.register("navigation", "1", function() {
// ... open the first link in the navigation
});
```The zone is now ready to be activated, and this can be done
programitically by the `focusDomain()` method (see below).# API
- register([name], key, handler)
Add a paricular key binding.
If the name value is specified this is used as a shorthand
form for the creation of a domain and the key is added to it.- focusDomain(name)
Make a particular domain and its associated keys active.
- addDomain(name)
Create a domain for the addition of keys.
- removeDomain(name)
Destroy a domain and all its associated key bindings.
# License
KeystrokeHandler is licensed under a standard 3-clause BSD license -- see
the `LICENSE`-file for details.