Linked Questions
- Listen - How can I listen for keypress event on the whole page?
- Override - How does Google Sheets override browser shortcuts?
I'm trying to create a web page that helps people build Macros for LUAMacros. part of this is to interpret Key presses within the browser, these may trigger browser shortcuts
<script>
document.body.addEventListener('keydown', (event) => {
event.preventDefault();
});
</script>
this will prevent the browser from responding to built in shortcuts. however also prevents the angular component listening to the key press
@HostListener('document:keypress', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
this.key = event.key;
console.log(this.key);
event.preventDefault();
}
Without the script, the browser responds to shortcuts, however with it the component will not fire the above host listener.
the components ' event.preventDefault();' appears to respond after the browser recognises the short cut.
Incidentally i'm trying to resolve [CTRL + k] which chrome uses for search.