MouseEvent getModifierState() method

Definition and usage

If the specified modifier key is pressed or activated, the getModifierState() method returns true.

Modifier keys that are activated only when pressed:

  • Alt
  • AltGraph
  • Control
  • Meta
  • Shift

Modifier keys that are activated when clicked and deactivated when clicked again:

  • CapsLock
  • NumLock
  • ScrollLock

Instance

Example 1

Is the Caps Lock key activated?

var x = event.getModifierState("CapsLock");

Try it yourself

Example 2

Is the shift key pressed?

var x = event.getModifierState("Shift");

Try it yourself

Syntax

event.getModifierState("modifierKey)

Parameter value

Parameter Description
modifierKey

Check if the key has been activated. Valid values:

  • "Alt"
  • "AltGraph"
  • "CapsLock"
  • "Control"
  • "Meta"
  • "NumLocK"
  • "ScrollLock"
  • "Shift"

Technical details

Return value: Boolean value, true if the specified modifier key is activated, otherwise false.
DOM version: DOM Level 3 Events

Browser support

The numbers in the table indicate the first browser version that fully supports this method.

Method Chrome IE Firefox Safari Opera
getModifierState() 30 9.0 15 10.1 17

Related Pages

HTML DOM Reference Manual:MouseEvent altKey Property

HTML DOM Reference Manual:MouseEvent ctrlKey Property

HTML DOM Reference Manual:MouseEvent metaKey Property