MouseEvent.getModifierState() is an instance method that returns whether a named modifier key is active for that mouse event. Learn the key strings, how it compares to shiftKey / ctrlKey / altKey / metaKey, lock keys, and five try-it labs.
01
Kind
Instance method
02
Returns
Boolean
03
Status
Baseline Widely available
04
Argument
Modifier key string
05
Case
Case-sensitive
06
Related
shiftKey family
Fundamentals
Introduction
Mouse events already expose four handy booleans: shiftKey, ctrlKey, altKey, and metaKey. getModifierState() is a more general query: pass a modifier name and get true or false—including lock keys such as Caps Lock.
JavaScript
element.addEventListener("click", (event) => {
console.log(event.getModifierState("Shift")); // true or false
});
💡
Beginner tip
MDN: see KeyboardEvent.getModifierState() for the full modifier list and platform notes. The mouse method works the same way for the modifiers that apply to mouse events.
Concept
Understanding the Method
MDN: MouseEvent.getModifierState() returns the current state of the specified modifier key—true if the modifier is active (pressed or locked), otherwise false.
Instance — call event.getModifierState(key) in a handler.
Boolean — active vs not active for that named modifier.
String argument — case-sensitive modifier key value (or "Accel").
Same idea as keyboard — details live on KeyboardEvent’s method.
Foundation
📝 Syntax
JavaScript
const active = mouseEvent.getModifierState(key);
Parameters
Name
Type
Description
key
String
A modifier key value from KeyboardEvent.key (case-sensitive), or "Accel".
Return value
A boolean: true if that modifier is active for the event; otherwise false.
MDN notes that for the four everyday modifiers, the dedicated properties (altKey, ctrlKey, metaKey, shiftKey) are often preferable. Use getModifierState when you need one API for many names—or lock-state keys.
Caution
⚠️ The "Accel" Virtual Modifier
getModifierState("Accel") is a virtual check: historically it meant “the platform shortcut modifier” (often Control on Windows/Linux, Command on Mac). Modern drafts treat "Accel" as effectively deprecated. Today it commonly returns true when ctrlKey or metaKey is true.
💡
Prefer explicit checks
For new code, write event.ctrlKey || event.metaKey (or getModifierState("Control") / getModifierState("Meta")) instead of relying on "Accel".
MouseEvent.getModifierState() is Baseline Widely available across modern browsers (MDN: since March 2019). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
MouseEvent.getModifierState()
Query named modifier keys on mouse events—great for lock keys and unified checks.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerPartial / older support varies
Limited
getModifierState()Excellent
Bottom line: Use getModifierState(key) for named modifiers; prefer shiftKey/ctrlKey/altKey/metaKey for the four everyday flags.
Wrap Up
Conclusion
event.getModifierState(key) asks whether a named modifier is active for that mouse event. Use it for lock keys and flexible queries; keep shiftKey / ctrlKey / altKey / metaKey for everyday branches.
Prefer shiftKey family for the four common modifiers
Use getModifierState for Caps Lock / Num Lock style checks
Write ctrlKey || metaKey instead of "Accel"
Test synthetic events with matching modifier options
❌ Don’t
Use lowercase "shift" and expect true
Rely on deprecated "Accel" in new products
Assume every lock key works identically on every OS
Replace clear if (e.shiftKey) with longer method calls for no reason
Forget that boolean properties are often enough
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about getModifierState()
Named modifier queries on mouse events.
5
Core concepts
🖱️01
Instance
method on event
Kind
✅02
Boolean
true / false
Return
⌨️03
Key string
case-sensitive
Arg
🔄04
Matches
shiftKey twins
Compare
🛡️05
Baseline
widely available
Status
❓ Frequently Asked Questions
It returns a boolean for one named modifier key 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 and details.
No. MDN marks MouseEvent.getModifierState() as Baseline Widely available (since March 2019). It is not Deprecated, Experimental, or Non-standard, so no status warning banner is needed for the method itself.
Case-sensitive KeyboardEvent.key values for modifiers, such as "Shift", "Control", "Alt", "Meta", "CapsLock", "NumLock", and others. The virtual string "Accel" is also accepted but is effectively deprecated in modern specs.
For the four common modifiers, event.shiftKey / ctrlKey / altKey / metaKey are clearer and enough. Prefer getModifierState when you need 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.
Did you know?
MDN’s KeyboardEvent example notes that even when authors demonstrate getModifierState("Alt") and friends, the dedicated altKey / ctrlKey / metaKey / shiftKey properties are often the clearer choice for those four modifiers.