KeyboardEvent: metaKey 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

KeyboardEvent.metaKey 只讀屬性,返回一個布林值,表示在事件發生時 Meta 鍵是否被按下(true)或未被按下(false)。某些作業系統可能會攔截該鍵,使其永遠不會被檢測到。

注意: 在 Macintosh 鍵盤上,這是 ⌘ Command 鍵。

注意: 在 Firefox 118 之前,⊞ Windows 鍵被視為“OS”鍵而不是“Meta”鍵。按下 ⊞ Windows 鍵時,KeyboardEvent.metaKey 返回 false

一個布林值。

示例

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

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

結果

規範

規範
UI 事件
# dom-keyboardevent-metakey

瀏覽器相容性

另見