Skip to content
索引

keyCode is deprecated

使用以下写法,ts会提示keyCode is deprecated

js
// 判断是否按住了shift键(左右都包括) 
window.addEventListener("keydown", code => {
      if (code.keyCode == 16) {
        ...
      }
    })
// 判断是否按住了shift键(左右都包括) 
window.addEventListener("keydown", code => {
      if (code.keyCode == 16) {
        ...
      }
    })

改为

js
 window.addEventListener("keydown", code => {
      if (code.key === "Shift") {
        ...
      }
    })
 window.addEventListener("keydown", code => {
      if (code.key === "Shift") {
        ...
      }
    })

Released under the MIT License.