event.metaKey property
The event.metaKey property lets
you know if the Cmd key was
pressed during the event. If pressed,
the property will return the value
true, otherwise - false.
Syntax
event.metaKey;
Example
In the following example, when a button is
clicked, we will display a message indicating
whether the Cmd key or the Ctrl,
Alt, Shift keys were pressed:
<button id="button">click me</button>
let button = document.querySelector('#button');
button.addEventListener('click', function(event) {
if (event.metaKey) {
alert('Cmd pressed');
}
if (event.ctrlKey) {
alert('Ctrl pressed');
}
if (event.altKey) {
alert('Alt pressed');
}
if (event.shiftKey) {
alert('Shift pressed');
}
});
:
See also
-
the
event.ctrlKeyproperty
that catches pressing the Ctrl key -
the
event.shiftKeyproperty
that catches pressing the Shift key -
the
event.altKeyproperty
that catches pressing the Alt key -
the
codeproperty
that gets the code of a pressed key -
the
event.keyproperty
that gets an entered character