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

浏览器兼容性

另见