offline version v3


218 of 264 menu

event.altKey property

The event.altKey property lets you know if the Alt key was pressed during the event.

Syntax

event.altKey;

Example

In the following example, when a button is clicked, we will display a message indicating whether one of the Ctrl, Alt or Shift keys was pressed:

<button id="button">click me</button> let button = document.querySelector('#button'); button.addEventListener('click', function(event) { if (event.ctrlKey) { alert('Ctrl pressed'); } if (event.altKey) { alert('Alt pressed'); } if (event.shiftKey) { alert('Shift pressed'); } });

:

See also

enru