Is the Caps Lock key activated?
var x = event.getModifierState("CapsLock");
Try it Yourself »
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:
Modifier keys that are activated when they are clicked, and deactivated when they are clicked again:
event.getModifierState(
modifierKey)
Parameter | Description |
---|---|
modifierKey | The key to check if is activated or not. Legal Values: "Alt" "AltGraph" "CapsLock" "Control" "Meta" "NumLocK" "ScrollLock" "Shift" |
Return Value: | A Boolean. Returns true if the modifier key is activatedOtherwise it returns false . |
---|---|
DOM Version: | DOM Level 3 Mouse Events. |
Is the shift key breing pressed down?
var x = event.getModifierState("Shift");
Try it Yourself »
HTML DOM reference: MouseEvent altKey Property
HTML DOM reference: MouseEvent ctrlKey Property
HTML DOM reference: MouseEvent metaKey Property
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 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!