mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 03:01:12 +00:00
44 lines
1.1 KiB
JavaScript
Vendored
44 lines
1.1 KiB
JavaScript
Vendored
export const ctrlPressed = {
|
|
data() {
|
|
return {
|
|
isCtrlCommandPressed: false
|
|
};
|
|
},
|
|
|
|
created() {
|
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
this.handleKeyUp = this.handleKeyUp.bind(this);
|
|
this.handleBlur = this.handleBlur.bind(this);
|
|
},
|
|
|
|
mounted() {
|
|
document.addEventListener('keydown', this.handleKeyDown);
|
|
document.addEventListener('keyup', this.handleKeyUp);
|
|
window.addEventListener('blur', this.handleBlur);
|
|
},
|
|
|
|
beforeDestroy() {
|
|
document.removeEventListener('keydown', this.handleKeyDown);
|
|
document.removeEventListener('keyup', this.handleKeyUp);
|
|
window.removeEventListener('blur', this.handleBlur);
|
|
},
|
|
|
|
methods: {
|
|
handleKeyDown(event) {
|
|
if (event.ctrlKey || event.metaKey) {
|
|
this.isCtrlCommandPressed = true;
|
|
}
|
|
},
|
|
|
|
handleKeyUp(event) {
|
|
if (!event.ctrlKey && !event.metaKey) {
|
|
this.isCtrlCommandPressed = false;
|
|
}
|
|
},
|
|
|
|
handleBlur() {
|
|
this.isCtrlCommandPressed = false;
|
|
}
|
|
}
|
|
};
|