220 of 264 menu

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.ctrlKey property
    that catches pressing the Ctrl key
  • the event.shiftKey property
    that catches pressing the Shift key
  • the event.altKey property
    that catches pressing the Alt key
  • the code property
    that gets the code of a pressed key
  • the event.key property
    that gets an entered character
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline