Is there any way to disable the keyboard keys using Angular 2+(Typescript). I want to disable all keys in keyboard. But, the keys should be work on HTML input fields.
Import this HostListener
import { HostListener } from '@angular/core';
Then, put this code to prevent keyboard keys..
@HostListener('document:keydown', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
console.log(event);
event.returnValue = false;
event.preventDefault();
//or
//do something
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With