Is there any file/class holding constants for each keyboard events?
I think you want
if (event.key === KeyEventEnum.Enter) {
...
}
or
if (event.key === KeyEventEnum.Escape) {
...
}
or
if (event.key === KeyEventEnum.Shift) {
...
}
or
if (event.key === KeyEventEnum.Ctrl) {
...
}
instead of you are using like
if (event.key === "Enter") {
...
}
Angular doesn't have any constant or enum to hold all key code in one place but if you want any enum or constant then you please visit once to below link might be it help you. Its a angular package that you have to include it in your project.
https://github.com/nfriend/ts-keycode-enum
Use event.key
instead of event.keyCode
, keyCode
returns 13
for enter and event.key
returns "Enter"
string
HostListener('window:keyup', ['$event'])
onKeyUp(event: KeyboardEvent) {
if (event.key === "Enter") {
this.onEnterClicked(event);
}
}