import { Component } from '@angular/core';
import { NgZone } from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'ng';


  constructor(
    private ngZone: NgZone,
  ) {
    this.ngZone.runOutsideAngular(() => {
      document.addEventListener('keydown', this.handleKeydown.bind(this), true);
    });
  }

  handleKeydown(event: KeyboardEvent) {
    if (event.target instanceof HTMLInputElement && /^F[1-9]|F1[0-2]$/.test(event.key)) {
      event.preventDefault();
    }
    if (/^F[1-9]|F1[0-2]$/.test(event.key)) {
      event.preventDefault();
    }
  }

  // コンポーネントが破棄されるときにリスナーを削除
  ngOnDestroy() {
    document.removeEventListener('keydown', this.handleKeydown.bind(this));
  }
}
