vue3在函数中监听键盘事件


    /**
     * 键盘监听
     */
     const keyDown = () => {
      document.onkeydown = (e) => {
        let lock=0;
        let e1 = e || window.event || arguments.callee.caller.arguments[0]
        switch (e.code) {
          case "KeyW":
            value.value[options_model.value].y++
            break;
          case "KeyA":
          value.value[options_model.value].x--
            break;
          case "KeyS":
          value.value[options_model.value].y--
            break;
          case "KeyD":
          value.value[options_model.value].x++
            break;
          default:
            lock=1
            break;
        }
      }
    }
onMounted(() => {
keyDown()
})

声明:小小博客|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - vue3在函数中监听键盘事件


Carpe Diem and Do what I like