It seems like onkeyup
doesn't fire while holding command (at least in chrome on a mac). Is there anyway to get when any key is let go (onkeyup) while holding command?
Observe below:
If you hold command then press a character key, when you let of the character key, an onkeyup
event doesn't fire.
document.addEventListener('keyup', (e) => {
const {key, metaKey} = e;
console.log({key, metaKey});
})
Specifically, I'm trying to see if the user is about holding z
in while performing an Cmd + z
keyboard shortcut. In my UI, I also have a clickable undo button. While the user is holding cmd + z
, I want to style the button in an :active
state but when they let go of z
(while still possibly holding cmd
), I want to remove that active state.
To clarify: I know how to check for a cmd + z
in a keyboard event. Now I want an event after the user presses cmd + z
to let me know when they let go of z while they could still be holding cmd
.
To do that, I thought I could listen for keyup
events but the keyup
event doesn't seem to fire while holding cmd
.
What am I missing and how can I get around this?