I have a context menu in my Angular app, and I want to trigger a callback whenever a key is pressed while that context menu is open. I added the following code inside the constructor of my context menu:
window.addEventListener('keydown', function() {
console.log('keys pressed');
});
If I open the context menu, hover the cursor over it, and press a key, it successfully triggers this callback. However, if I move the mouse off the menu, it no longer triggers it when I press a key. Moreover, even if I move the mouse back over the menu, it still doesn't respond. I want it to respond when I press a key no matter where the cursor is, as long as the context menu is open.
Any ideas?