event.altKey property

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

Syntax

javascriptevent.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:

html<button id="button">click me</button>
javascriptlet 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