Is the Caps Lock key activated?
var x = event.getModifierState("CapsLock");
<!DOCTYPE html> <html> <body> <input type="text" size="40" onmousedown="myFunction(event)"> <p id="demo"></p> <script> function myFunction(event) {/*w w w . java 2s.c om*/ var x = event.getModifierState("CapsLock"); document.getElementById("demo").innerHTML = "Caps Lock activated: " + x; } </script> </body> </html>
The getModifierState()
method returns true if the specified modifier key was pressed, or activated.
Modifier keys that are activated only when they are being pressed down:
Alt
AltGraph
Control
Meta
Shift
Modifier keys that are activated when they are clicked, and deactivated when they are clicked again:
CapsLock
NumLock
ScrollLock
getModifierState(modifierKey);
Parameter Values
Parameter | Description |
---|---|
modifierKey The key to check if is activated or not.Legal Values: Alt AltGraph CapsLock Control Meta NumLocK ScrollLock Shift |