MDN self-hosted library · e01.org

KeyboardEvent: metaKey property

UI Events

Open notebook · 2 cells web-api-instance-property upstream source

UI Events

The KeyboardEvent.metaKey read-only property returning a boolean value that indicates if the Meta key was pressed (true) or not (false) when the event occurred. Some operating systems may intercept the key so it is never detected.

[!NOTE] On Macintosh keyboards, this is the ⌘ Command key.

[!NOTE] Before Firefox 118, the ⊞ Windows key was handled as an "OS" key rather than the "Meta" key. KeyboardEvent.metaKey was false when the ⊞ Windows key was pressed.

When the Meta key itself is pressed or released, this property is true for its keydown event and false for its keyup event, because both events fire after the state change.

Value

A boolean value.

Examples

<button>Click me with the meta key</button>

<p id="output"></p>
document.querySelector("button").addEventListener("click", (e) => {
  document.querySelector("#output").textContent =
    `metaKey pressed? ${e.metaKey}`;
});

Result

400

Specifications

Browser compatibility

See also

  • KeyboardEvent