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.ctrlKeyproperty
that catches pressing the Ctrl key -
the
event.altKeyproperty
that catches pressing the Alt key -
the
event.metaKeyproperty
that catches pressing the Cmd key -
the
codeproperty
that gets the code of a pressed key -
the
event.keyproperty
that gets an entered character