KeyboardEvent: metaKey property
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{APIRef("UI Events")}}
The **KeyboardEvent.metaKey** read-only property returning a boolean value that indicates if the <kbd>Meta</kbd> key was pressed (true) or not (false) when the event occurred. Some operating systems may intercept the key so it is never detected.
توجه: On Macintosh keyboards, this is the <kbd>⌘ Command</kbd> key.
توجه: Before Firefox 118, the <kbd>⊞ Windows</kbd> key was handled as an "OS" key rather than the "Meta" key. KeyboardEvent.metaKey was false when the <kbd>⊞ Windows</kbd> key was pressed.
When the <kbd>Meta</kbd> key itself is pressed or released, this property is true for its {{domxref("Element/keydown_event", "keydown")}} event and false for its {{domxref("Element/keyup_event", "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
{{ EmbedLiveSample('Examples', 400, 90) }}
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- {{ domxref("KeyboardEvent") }}