Profile picture of Michael GroßklausMichael Großklaus

TIL: Detecting capslock with JavaScript

window.addEventListener("keydown", detectCapsLock);
window.addEventListener("keyup", detectCapsLock);

function detectCapsLock(e) {
if (e.getModifierState("CapsLock")) {
// caps lock is on
} else {
// caps lock is off
}
}