@wbiokr/keybinding
v2.0.5
Published
快捷键定制
Downloads
215
Readme
1. 键盘事件监听
1.1 基础类Keybinding
| 参数 | Type | 默认值 | Description | | ----- | ------------- | ------------- | ------------------------ | | namespace | String | global | 参数1:当前实例的命名空间 | | dom | element | document | 参数2:键盘事件的主体 | | eventType | string | keydown | 参数3:事件类型(keydown、keyup) |
import { Keybinding } from '@wbiokr/keybinding'
const instance = new Keybinding('header', document.querySelect('#header'))
instance.on('a', () => { alert('退出事件'); instance.off('a') })
instance.on('b', () => { alert('b') })
instance.on('c', () => { alert('清空事件'); instance.clear() })
instance.on('esc', () => { alert('解除绑定'); instance.unbind() })
1.2 快速实例
keydowns---基于document的keydown对象;
keyups---基于document的keyup对象;
import { keydowns, keyups } from '@wbiokr/keybinding'
keydowns.on('a', () => alert('down-a'))
keyups.on('a', () => alert('up-a'))
keyups.on('b', () => alert('up-b'), true)
keydowns.off('a')
keyups.off('a')
keyups.off('b', true)