Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Disable Keyboard Keys Using Angular 2+. But, The keys should be work on HTML input fields

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.

like image 809
Sakkeer A Avatar asked May 08 '18 10:05

Sakkeer A


1 Answers

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

}
like image 124
Sakkeer A Avatar answered Sep 18 '22 20:09

Sakkeer A