JSPM

angular-keydown

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q22239F
  • License ISC

Angular service for keydown detection

Package Exports

  • angular-keydown

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (angular-keydown) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

angular-keydown

Angular service for keydown detection

npm version Build Status Code Climate Test Coverage

devDependency Status

Sometimes, it could be useful to detect a pressed key during a click or another event. Let's say you have a validation button. It would rock if it pops up a confirmation message when you click on it, but not if you hold the shift key, right ?

Angular-keydown makes it really easy!

Demos & usage

http://msieurtoph.github.io/angular-keydown

Installation

npm i angular-keydown --save

Usage

Please, visit http://msieurtoph.github.io/angular-keydown for live examples.

angular.module('', ['msieurtoph.ngKeydown'])

.directive('myTest', ['Keydown', function(Keydown){
    return {
        restrict: 'A',
        link: function(scope){
            scope.click = function(){
                if (Keydown.shift){
                    scope.message = 'Shift key has been pressed when clicking!';
                } else {
                    scope.message = 'Shift key nas not been pressed when clicking!';
                }
            };
        }
    }]);
});
<button my-test ng-click="click()">Hold shift key and click me</button>
<pre ng-bind="message"></pre>

The service lets you know whether the following keys are pressed :

  • shift, ctrl, alt
  • up, down, right, left arrows
  • pgUp, pgDown
  • space, escape, enter, tab

For other keys you can look to Keydown.others[_theKeyCode_] For instance, Keydown.others[65] will equal true if the a key is down.

Keydown.pressed gives you the list of pressed keys. For instance, if a, b and c keys are down, Keydown.pressed will equal [65, 66, 67]