MouseEvent: metaKey property
BaselineWidely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers sinceJuly 2015.
TheMouseEvent.metaKey
read-only property is a boolean value that indicates whether themetakey was pressed or not when a given mouse event occurs.
Be aware that many operating systems bind special functionality to themetakey, so this property may befalse
even when the key is actually pressed.
On Windows, for example, this key may open the Start menu.
Note:On Macintosh keyboards, this key is thecommandkey (⌘). On Windows keyboards, this key is the Windows key (⊞).
Value
A boolean value, wheretrue
indicates that the key is pressed, andfalse
indicates that the key isnotpressed.
Examples
This example logs themetaKey
property when you trigger aclick
event.
HTML
<p>Click anywhere to test the<code>metaKey</code>property.</p>
<pid="log"></p>
JavaScript
letlog=document.querySelector("#log");
document.addEventListener("click",logKey);
functionlogKey(e){
log.textContent=`The meta key is pressed:${e.metaKey}`;
}
Result
Specifications
Specification |
---|
UI Events #dom-mouseevent-metakey |
Browser compatibility
BCD tables only load in the browser