uniapp-keyboard-listener
v1.0.4
Published
uni-app 全局按键事件监听
Downloads
50
Maintainers
Readme
uniapp-keyboard-listener
uni-app 全局按键事件监听。
支持App端和H5端,一般用于监听硬件设备(键盘、扫描枪)按键事件。
使用方式
NPM
npm i uniapp-keyboard-listener --save
import keyboardListener from 'uniapp-keyboard-listener'
export default {
components: {
keyboardListener
}
}
直接下载
// 以下路径需根据项目实际情况填写
import keyboardListener from '../../components/keyboard-listener'
export default {
components: {
keyboardListener
}
}
事件
事件对象基本和浏览器事件 KeyboardEvent 一致
keydown
监听按键按下事件
<keyboard-listener @keydown="onKeydown"></keyboard-listener>
keyup
按键松开事件
<keyboard-listener @keyup="onKeyup"></keyboard-listener>
提示
- 移动端软键盘无法判断具体按键(仅可判断 Enter 等)
- 示例工程 uniapp-keyboard-listener-demo 需要先安装 NPM 依赖。