I have a simple function that checks if CapsLock was on input
document.addEventListener('keydown', function(e) {
if(e.getModifierState("CapsLock")) {
console.log('CapsLock is on')
} else {
console.log('Capslock is off')
}
});
To test the function I tried to trigger it this way:
document.dispatchEvent(new KeyboardEvent('keydown', {key:'A', capsLockKey: true}));
But it's not working
How can I trigger new Keyboard Event with CapsLock property?
I found the solution on W3C page
document.dispatchEvent(new KeyboardEvent('keydown', {key:'A', modifierCapsLock: true}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With