欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 维修 > uniapp小程序监听外接扫描枪

uniapp小程序监听外接扫描枪

2025/2/25 1:31:33 来源:https://blog.csdn.net/hu104160112/article/details/142910451  浏览:    关键词:uniapp小程序监听外接扫描枪

场景:uniapp打包的app在手持设备上使用,手持设备外接扫描枪,快速扫描

关键:扫描枪一般是触发 键盘事件keydown或keyup

无输入框式

import keymap from './keymap'
export default {data() {return {inputString: '',inputCache: ''}},mounted() {// #ifdef APP-PLUSplus.key.addEventListener("keyup", this.keypress);// #endif },beforeDestroy() {// #ifdef APP-PLUSplus.key.removeEventListener("keyup", this.keypress);// #endif },deactivated() {// #ifdef APP-PLUSplus.key.removeEventListener("keyup", this.keypress);// #endif },methods: {keypress(e) {if (e.keyCode === 66 || e.key === 'Enter') { this.inputString = this.inputCache;this.onConfirm(this.inputString);this.inputCache = '';} else {this.inputCache +=keymap[e.keyCode] || '';}}onConfirm(code) {console.log('拿到的code', code);//写你的逻辑},}
}

keymap.js

export default {"7": "0","8": "1","9": "2","10": "3","11": "4","12": "5","13": "6","14": "7","15": "8","16": "9","29": "A","30": "B","31": "C","32": "D","33": "E","34": "F","35": "G","36": "H","37": "I","38": "J","39": "K","40": "L","41": "M","42": "N","43": "O","44": "P","45": "Q","46": "R","47": "S","48": "T","49": "U","50": "V","51": "W","52": "X","53": "Y","54": "Z","55": ",","56": ".","59": "","69": "-","70": "=","81": "+"
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词