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.metaKeyread-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 befalseeven 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, wheretrueindicates that the key is pressed, andfalseindicates that the key isnotpressed.

Examples

This example logs themetaKeyproperty when you trigger aclickevent.

HTML

html
<p>Click anywhere to test the<code>metaKey</code>property.</p>
<pid="log"></p>

JavaScript

js
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

See also