속성 event.metaKey

속성 event.metaKey는 이벤트 발생 시 Cmd 키가 눌렸는지 확인할 수 있게 합니다. 눌렸다면 속성은 true 값을 반환하고, 그렇지 않다면 false를 반환합니다.

구문

javascriptevent.metaKey;

예제

다음 예제에서는 버튼을 클릭할 때 Cmd 키 또는 Ctrl, Alt, Shift 키가 눌렸는지 메시지를 출력합니다:

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

button.addEventListener('click', function(event) {
  if (event.metaKey) {
    alert('Cmd 키가 눌렸습니다');
  }
  
  if (event.ctrlKey) {
    alert('Ctrl 키가 눌렸습니다');
  }
  
  if (event.altKey) {
    alert('Alt 키가 눌렸습니다');
  }
  
  if (event.shiftKey) {
    alert('Shift 키가 눌렸습니다');
  }
});

Результат:

참고 항목

  • Ctrl 키 눌림을 감지하는 속성 event.ctrlKey,
  • Shift 키 눌림을 감지하는 속성 event.shiftKey,
  • Alt 키 눌림을 감지하는 속성 event.altKey,
  • 눌린 키의 코드를 가져오는 속성 code,
  • 입력된 문자를 가져오는 속성 key,