본문 바로가기
WWWEB/Script

[js] keyCode는 그만 쓰자!

by 미니토이 2024. 1. 16.

 

요약: keyCode 대신 code를 사용하자

 

 

 

KeyboardEvent: keyCode

 

 

 

KeyboardEvent: keyCode property - Web APIs | MDN

The deprecated KeyboardEvent.keyCode read-only property represents a system and implementation dependent numerical code identifying the unmodified value of the pressed key.

developer.mozilla.org

 

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

 

(Deprecated(사용하지 않음): 이 기능은 더 이상 권장 안 함. 일부 브라우저는 여전히 지원할 수 있지만 웹 표준에서 이미 제거되었거나 삭제 중이거나 호환성 목적으로만 유지될 수 있으니, 사용을 피하고 가능하면 기존 코드를 업데이트 하는게 좋을껄? keyCode는 언제든지 작동하지 않을 수 있음 주의~)

 

 

 

You should avoid using this if possible; it's been deprecated for some time. Instead, you should use KeyboardEvent.code, if it's implemented. Unfortunately, some browsers still don't have it, so you'll have to be careful to make sure you use one which is supported on all target browsers.

 

(대신 KeyboardEvent.code를 써야하는데,

일부 브라우저는 아직 지원 안 할 수도 있음.)

 

 

 

 

KeyboardEvent: code

 

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code

 

KeyboardEvent: code property - Web APIs | MDN

The KeyboardEvent.code property represents a physical key on the keyboard (as opposed to the character generated by pressing the key). In other words, this property returns a value that isn't altered by keyboard layout or the state of the modifier keys.

developer.mozilla.org

 

 

 

 

KeyboardEvent: key

 

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key

 

KeyboardEvent: key property - Web APIs | MDN

The KeyboardEvent interface's key read-only property returns the value of the key pressed by the user, taking into consideration the state of modifier keys such as Shift as well as the keyboard locale and layout.

developer.mozilla.org

 

 

 

 

아무튼, 그동안 keyCode로 사용하고 있었는데, 틈틈히 코드 업데이트를 진행해야 할 듯.

728x90
반응형

댓글