Свойство event.altKey

Свойство event.altKey воқеа paytida Alt тугмаси босилган-босилмаганини аниқлаш имконини беради.

Синтаксис

javascriptevent.altKey;

Мисол

Куйидаги мисолда тугмани босганда, Ctrl, Alt ёки Shift тугмаларининг бирортаси босилган-босилмагани хак̌ида хабар чиқарамиз:

html<button id="button">click me</button>
javascriptlet button = document.querySelector('#button');

button.addEventListener('click', function(event) {
  if (event.ctrlKey) {
    alert('Ctrl босилди');
  }
  
  if (event.altKey) {
    alert('Alt босилди');
  }
  
  if (event.shiftKey) {
    alert('Shift босилди');
  }
});

Результат:

Қараш

  • свойство event.ctrlKey,
    which detects the pressing of the Ctrl key
  • свойство event.shiftKey,
    which detects the pressing of the Shift key
  • свойство event.metaKey,
    which detects the pressing of the Cmd key