MouseEvent.getModifierState(key) returns true if the named modifier is active (pressed or locked) for that event, otherwise false(MDN). Details of key names match KeyboardEvent.getModifierState().
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call event.getModifierState. Start with this line.
JavaScript
event.getModifierState(key)
Call
What it does
event.getModifierState(key)
Primary signature.
event.getModifierState(...)
Call with the arguments your case needs.
Built into the browser. Call getModifierState(...) on a MouseEvent — no import required.
Library declarations
JavaScript
event.getModifierState(key)
Parameters
Parameter
Description
key
Required. Case-sensitive modifier name
Return Value
Return Value
Description
*
boolean
JavaScript Examples
Example 1 — Check Shift on Click
Read getModifierState("Shift") in a click handler.
MouseEvent.getModifierState() is marked Baseline Widely available on MDN (since March 2019).
✓ Baseline · Widely available
MouseEvent.getModifierState()
Returns whether a named modifier is active on a mouse event. Key names match KeyboardEvent.getModifierState(). Avoid deprecated Accel.
100%Widely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
getModifierStateExcellent
Bottom line: Safe everyday API. Use exact key casing; prefer *Key properties for Shift/Ctrl/Alt/Meta. See the MDN getModifierState reference.
Frequently Asked Questions
It returns a boolean for one named modifier on that mouse event: true if the modifier is active (pressed or locked), otherwise false. MDN points to KeyboardEvent.getModifierState() for the full key list.
No. MDN marks MouseEvent.getModifierState() as Baseline Widely available (since March 2019). It is not Deprecated, Experimental, or Non-standard. The virtual "Accel" string is effectively deprecated in modern specs.
Case-sensitive KeyboardEvent.key values for modifiers, such as "Shift", "Control", "Alt", "Meta", "CapsLock", and "NumLock". Wrong casing (for example "shift") typically returns false.
For the four common modifiers, event.shiftKey / ctrlKey / altKey / metaKey are clearer. Prefer getModifierState for lock keys (CapsLock, NumLock) or one API that can query many modifier names.
Yes. Pass "Shift", not "shift". Wrong casing typically returns false.
Yes for the usual modifiers when you set options like { shiftKey: true }. Then event.getModifierState("Shift") is typically true, matching event.shiftKey.