offline version v3


219 of 264 menu

event.shiftKey property

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

Syntax

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

<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

  • 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
enru