배운 내용 정리/JAVASCRIPT

KeyBoardEvent (getModifierState) - 키보드 이벤트(예: Caps Lock 여부)

만타가올이 2020. 12. 7. 09:10

developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/getModifierState

 

KeyboardEvent.getModifierState()

The KeyboardEvent.getModifierState() method returns the current state of the specified modifier key: true if the modifier is active (that is the modifier key is pressed or locked), otherwise, false.

developer.mozilla.org

Caps Lock, Fn 키 등이 켜져 있는지의 여부를 키보드 이벤트

getModifierState 메소드로 확인할 수 있다

 

사용예시)

function 함수명(e) {

    if(e.getModifierState('CapsLock')){

       alert('CapsLock이 켜져있습니다');

    }

}