How to use keyboard keys combination in angular hostlistener

2.8k views Asked by At

When the user pressing keys ALT+M then ALT+E, I want show mat dialog modal.

1

There are 1 answers

0
SaiSurya On

According to your question to capture ALT+M and ALT+E

    @HostListener('window:keydown.Alt.m', ['$event']) 
    onKeyDownAltM(e) {
      e.preventDefault();
      console.log(e);    
       console.log('ALT + M');
   }
   @HostListener('window:keydown.Alt.e', ['$event']) 
    onKeyDownAltE(e) {
      e.preventDefault();
      console.log(e);    
       console.log('ALT + E');
   }

That's it you are good to go!
For Key Codes Reference
Stack Blitz working example Link