--- title: KeyboardEvent.metaKey slug: Web/API/KeyboardEvent/metaKey tags: - API - MouseEvent translation_of: Web/API/KeyboardEvent/metaKey ---

{{APIRef("DOM Events")}}

KeyboardEvent.metaKey 为只读属性,返回一个 {{jsxref("Boolean", "布尔值")}},在事件发生时,用于指示 Meta 键是按下状态(true),还是释放状态(false)。

备注:在MAC键盘上,表示 Command 键(),在Windows键盘上,表示 Windows 键()。

语法

var metaKeyPressed = instanceOfKeyboardEvent.metaKey

返回值

一个布尔值

示例

 function goInput(e) {
 // 检测metaKey值
   if (e.metaKey) {
        // 继续处理事件
     superSizeOutput(e);
   } else {
     doOutput(e);
   }
 }

{{ EmbedLiveSample('Example', 400, 36) }}

规范

规范版本 规范状态 备注
{{SpecName('DOM3 Events','#widl-KeyboardEvent-ctrlKey','KeyboardEvent.ctrlKey')}} {{Spec2('DOM3 Events')}} Initial definition.

浏览器兼容性

{{Compat("api.KeyboardEvent.metaKey")}}

相关链接