d***@siankeji.com
d***@siankeji.com
  • 发布:2022-11-02 11:01
  • 更新:2022-11-02 11:01
  • 阅读:127

module="keyboard" lang="renderjs" 刷卡

分类:HBuilderX

最近需要触屏后才能监听键盘事件,怎么回事呢! (版本:3.4.18),以前都不需要。

代码如下:
mounted () {
const onKey = (event) => {
const keys1 = ['type', 'timeStamp']
const keys2 = ['altKey', 'code', 'ctrlKey', 'isComposing', 'key', 'location', 'metaKey', 'repeat', 'shiftKey']
const keys3 = ['char', 'charCode', 'keyCode', 'keyIdentifier', 'keyLocation', 'which']
const data = {}
keys1.concat(keys2, keys3).forEach(key => data[key] = event[key])
this.$ownerInstance.callMethod('onEvent', data)
}
const names = ['keydown', 'keyup']
names.forEach(name => {
document.addEventListener(name, onKey, false)
})
this.$on('hook:beforeDestroy', () => {
names.forEach(name => {
document.removeEventListener(name, onKey, false)
})
})
}

2022-11-02 11:01 负责人:无 分享
已邀请:

要回复问题请先登录注册