event.shiftKey property

The event.shiftKey property lets you know if the Shift key was pressed during the event.

Syntax

javascriptevent.shiftKey;

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

  • the event.ctrlKey property
    that catches pressing the Ctrl key
  • the event.altKey property
    that catches pressing the Alt key
  • the event.metaKey property
    that catches pressing the Cmd key
  • the code property
    that gets the code of a pressed key
  • the event.key property
    that gets an entered character