I want to handle the click click + CTRL keypress event in the same function in my component.ts file, but it seems I have not found a solution anywhere. I tried:
@HostListener("click")
onDropdownItemClick( evt: keyboardEvent) {
console.log(evt.keyCode);
}
but it just returns "ERROR TypeError: cannot read property" keyCode "from undefined"
I also tried this:
@Component({
selector: '....',
templateUrl: '....',
host: {
'(window:keydown)': 'findKey($event)',
'(window:mousedown)': 'findKey($event)'
}
});
findKey(event) {
if(event.ctrlKey && event.which === 1){
console.log("CTRL + mouse-click");
}
}
But it doesn’t work either. Anyone have suggestions on how to catch both events at the same time?
source
share