offline version v3


217 of 264 menu

event.ctrlKey property

The event.ctrlKey property allows you to find out if the Ctrl key was pressed during the event.

Syntax

event.ctrlKey;

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