vue制作快捷键
created() {let arr = [];let that = this;document.onkeydown = function(e) {if (arr.length > 0) {// a-z按键长按去重if (arr.indexOf(e.key.toLowerCase()) >= 0) {return;}}arr.push(e.key...
·
created() {
let arr = [];
let that = this;
document.onkeydown = function(e) {
if (arr.length > 0) {
// a-z按键长按去重
if (arr.indexOf(e.key.toLowerCase()) >= 0) {
return;
}
}
arr.push(e.key.toLowerCase());
this.keydown = arr.join("+");
// 监听按键捕获
if (this.keydown == "shift+enter" || this.keydown == "alt+arrowup") {
this.keydown = "";
// console.log(this.keydown,arr); do something
}
};
document.onkeyup = function(e) {
arr.splice(arr.indexOf(e.key.toLowerCase()), 1);
this.keydown = arr.join("+");
};
this.keydown = "";
}
created() {
let arr = [];
let that = this;
document.onkeydown = function(e) {
if (arr.length > 0) {
// a-z按键长按去重
if (arr.indexOf(e.key.toLowerCase()) >= 0) {
return;
}
}
arr.push(e.key.toLowerCase());
this.keydown = arr.join("+");
// 监听按键捕获
if (this.keydown == "shift+enter" || this.keydown == "alt+arrowup") {
this.keydown = "";
// console.log(this.keydown,arr); do something
}
};
document.onkeyup = function(e) {
arr.splice(arr.indexOf(e.key.toLowerCase()), 1);
this.keydown = arr.join("+");
};
this.keydown = "";
}
补充一点 想要知道哪个键 阔以自行打印
copy代码更爽
更多推荐
已为社区贡献14条内容
所有评论(0)