
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
angular-hotkeys-light
Advanced tools
Code-centric keyboard shortcuts for your Angular apps.
keydown
and keyup
events. (keydown
is the default)$ npm install angular-hotkeys-light --save
$ bower install angular-hotkeys-light --save
angular.module('myApp', ['fps.hotkeys']);
Creates hotkey
object based on given object
object
: An object with following parameters:
id
: {String} Hotkey's id. If it's not supplied, will be auto-generated. Used internaly.key
: {String} A key or key combination you what to bind a callback to. requiredcontext
: {Object} This object will be passed to a callback
as this
parametercallback
: {Function} This function will be invoked when key
is pressed. Passes two arguments: an event that triggered callback
and args
object requiredargs
: {Object} This object will be pass to callback
as a second argument####Note: Do not call $scope.$apply()
manually within a hotkey callback.
This method registers the hotkey object in the global table. If the given combination already exist it will append the hotkey to it. In the case when a combination has multiple callbacks they will be invoked in FIFO way.
// Create simple hotkey object
var hotkey = Hotkeys.createHotkey({
key: 'shift+1',
callback: function () {
console.log('You pressed shift+1 keys combination');
}
});
// Register the hotkey object
Hotkeys.registerHotkey(hotkey);
angular.module('myApp', [])
.directive('myDirective', function() {
return {
controllerAs: 'vm',
controller: function($scope, Hotkeys) {
var hotkey = Hotkeys.createHotkey({
key: 'escape',
callback: function () {
console.log('You pressed shift+1 keys combination');
}
});
Hotkeys.registerHotkey( hotkey);
// Very important to unregister the hotkey when `scope` gets destroyed
$scope.$on('$destroy', function(){
Hotkeys.deregisterHotkey(hotkey);
});
}
}
});
angular.module('myApp', [])
.service('MyService', function() {
var srv = this;
srv.importantMethod = function(){
// do important things
};
// invoke `importantMethod` when `f1` key pressed
var hotkey = Hotkeys.createHotkey({
key: 'f1',
context: srv,
callback: srv.importantMethod
});
Hotkeys.registerHotkey(hotkey);
});
Note: Unlike the directive we do not need to worry about deregestering a hotkey here, because a service never gets destroyed.
// Create hotkeys with shared callback
var hotkeys = Hotkeys.createHotkey({
key: ['ctrl+a', 'meta+a'],
callback: function (event) {
var key = Hotkeys.keyStringFromEvent(event);
console.log('You pressed %s key combination', key);
}
});
// Register hotkeys object
Hotkeys.registerHotkey(hotkeys);
Note: Calling deregisterHotkey
method on hotkey
object with multiple keys, will correctly deregister a callback for each key.
Same as registerHotkey
, instead a callback binded to keyup
event.
Removes specific hotkey
object from the global hotkey table. Removed object will be returned within the array, otherwise return null.
Extracts a key string from keydown
and keyup
events. Note: Do not use this method within keypress
event, since it reveals different keyCode values.
document.addEventListener('keydown', function(event) {
var combo = Hotkeys.keyStringFromEvent(event);
console.log(combo); // Ex: 'ctrl+c'
});
Checks given shortcut against the event and return true
when find a match. Helful to use in conjunction with user input elements like: input, textarea, etc.
textarea.addEventListener('keydown', function(event) {
if (Hotkeys.match(event, 'escape')) {
event.preventDefault();
event.target.value = '';
}
if (Hotkeys.match(event, ['ctrl+enter', 'meta+enter'])) {
event.prevetDefault();
// do something
}
});
backspace
, tab
, enter
, shift
, ctrl
, alt
, pause
, caps
, escape
, space
, pageup
, pagedown
, end
, home
, left
, up
, right
, down
, insert
, delete
Including functional keys from f1
to f12
The MIT License
Copyright (c) 2016 Eugene Brodsky
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Keyboard shortcuts for your Angular applications
We found that angular-hotkeys-light demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.