MouseEvent getModifierState() Method
Example
Is the Caps Lock key activated?
var x = event.getModifierState("CapsLock");
Try it Yourself »
Description
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
Syntax
event.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" |
Technical Details
Return Value: |
A Boolean. Returns true if the modifier key is activatedOtherwise it returns false . |
---|---|
DOM Version: | DOM Level 3 Mouse Events. |
More Examples
Example
Is the shift key breing pressed down?
var x = event.getModifierState("Shift");
Try it Yourself »
Related Pages
HTML DOM reference: MouseEvent altKey Property
HTML DOM reference: MouseEvent ctrlKey Property
HTML DOM reference: MouseEvent metaKey Property
Browser Support
event.getModifierState
is a DOM Level 3 (2004) feature.
It is fully supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 11 |
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.