@aurouscia/keyboard-shortcut
v3.0.0
Published
简易键盘事件监听小工具
Readme
键盘快捷键监听小工具
用法
初始化
constructor(callback: CallBack, options: AuShortcutListenerOptions)
type CallBackExpectReturnType = void | undefined | { dontPrevent?: boolean }// dontPrevent:字面意思
type CallBack = () => CallBackExpectReturnType
interface AuShortcutListenerOptions {
code: string // KeyboardEvent的code属性,如果不清楚,应该查找某键对应的code值
ctrl?: boolean
shift?: boolean
alt?: boolean
target?: HTMLElement
}页面/编辑器加载完成时:
const shortcut = new AuShortcutListener(...)
shortcut.start()页面/编辑器离开时:
shortcut.dispose()将会removeEventListener,不再preventDefault
releaseNote
1.0.0更新
callback不能再传入异步的,必须是同步的(因为究竟要不要prevent必须立刻回答)
2.0.0更新
- 修改构造函数,改为传入
options配置对象 - 将meta键(command键)视为ctrl键
3.0.0更新
- 将
key属性改为更稳定的code属性
