KeyboardEvent getModifierState() Method

❮ DOM Events ❮ KeyboardEvent

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

Browser Support

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

Method
getModifierState() 30 9.0 15 10.1 17


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, true if the specified modifier key is activated, otherwise false.
DOM Version: DOM Level 3 Events

More Examples

Example

Is the shift key breing pressed down?

var x = event.getModifierState("Shift");
Try it Yourself »

Related Pages

HTML DOM reference: KeyboardEvent keyCode Property

HTML DOM reference: KeyboardEvent which Property

HTML DOM reference: KeyboardEvent charCode Property


❮ DOM Events ❮ KeyboardEvent

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.