Skip to content

Instantly share code, notes, and snippets.

@senthilmpro
Created November 21, 2019 06:46
Show Gist options
  • Save senthilmpro/83444c8a4ccc8e074dbbb47d43a3a6fd to your computer and use it in GitHub Desktop.
Save senthilmpro/83444c8a4ccc8e074dbbb47d43a3a6fd to your computer and use it in GitHub Desktop.
angular-keypress-together.js
export class AppComponent {
title = 'ui';
keys = {
space : false,
ctrl : false
}
@HostListener('window:keydown', ['$event'])
keyEventDown(event: KeyboardEvent) {
if(event.keyCode === 17){
this.keys.ctrl = true;
}
if(event.keyCode === 32){
this.keys.space = true;
}
if(this.keys.ctrl && this.keys.space){
console.log("keys pressed");
}
}
@HostListener('window:keyup', ['$event'])
keyEventUp(event: KeyboardEvent) {
if(event.keyCode === 17){
this.keys.ctrl = false;
}
if(event.keyCode === 32){
this.keys.space = false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment