Created
November 21, 2019 06:46
-
-
Save senthilmpro/83444c8a4ccc8e074dbbb47d43a3a6fd to your computer and use it in GitHub Desktop.
angular-keypress-together.js
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
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