This commit is contained in:
lzp
2026-03-17 09:56:58 +08:00
parent 04be0b5930
commit fbab5f4e8d
5 changed files with 25 additions and 11 deletions

View File

@@ -2,11 +2,12 @@ export class KeyEventManager {
stateManager: any
constructor(options) {
this.stateManager = options.stateManager;
this.registerEvents()
this._handleKeyDown = this.handleKeyDown.bind(this)
}
onMounted() { }
/** 处理键盘事件 */
_handleKeyDown: any
handleKeyDown(event: any) {
const ctrl = event.ctrlKey ? 'ctrl-' : "";
const shift = event.shiftKey ? 'shift-' : "";
@@ -24,11 +25,11 @@ export class KeyEventManager {
}
/** 注册事件 */
registerEvents() {
document.addEventListener('keydown', this.handleKeyDown.bind(this))
document.addEventListener('keydown', this._handleKeyDown)
}
/** 删除事件 */
removeEvents() {
document.removeEventListener('keydown', this.handleKeyDown.bind(this))
document.removeEventListener('keydown', this._handleKeyDown)
}
dispose() {
this.removeEvents()