Created
March 2, 2019 15:04
-
-
Save ingeit/98f68d63329046b9d478e06b99477449 to your computer and use it in GitHub Desktop.
hotkeys shortcut keyboard key board combination angular javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VERSION LIGTH VANILLA JAVASCRIPT FUENTE: https://www.npmjs.com/package/hotkeys-js | |
// teclas posibles Supported Keys | |
//HotKeys understands the following modifiers: ⇧, shift, option, ⌥, alt, ctrl, control, command, and ⌘. | |
//The following special keys can be used for shortcuts: backspace, tab, clear, enter, return, esc, escape, space, up, down, left, right, home, end, pageup, pagedown, del, delete and f1 through f19. | |
<script src="https://unpkg.com/hotkeys-js/dist/hotkeys.min.js"></script> | |
<script type="text/javascript"> | |
hotkeys('ctrl+a,ctrl+b,r,f', function(event,handler) { | |
switch(handler.key){ | |
case "ctrl+a":alert('you pressed ctrl+a!');break; | |
case "ctrl+b":alert('you pressed ctrl+b!');break; | |
case "r":alert('you pressed r!');break; | |
case "f":alert('you pressed f!');break; | |
} | |
}); | |
</script> | |
version angular | |
// fuente: https://www.npmjs.com/package/keypress-combination | |
//npm install keypress-combination | |
import * as KeypressCombinationEmitter from "keypress-combination"; | |
//definir variable dentro de la clase | |
emitter = new KeypressCombinationEmitter(); | |
//funcion dentro de la clase.. en este caso escucha la combinacion CTRL + ALT + F1 | |
subscription = this.emitter.addListener(18, 17, 112, () => { | |
// CTRL Keycode: 17 | |
// alt: 18 | |
// F1: 112 | |
console.log("Pressed "); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment