Skip to content

Commit

Permalink
Add clean shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
tiger2005 committed May 5, 2022
1 parent 45d8516 commit 724fb22
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README-zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ npm rebuild --runtime=electron --target=12.0.0 --disturl=https://atom.io/downloa
| antiMinimize | boolean | 在尝试最小化时自动复原 |
| bounceTime | number | 一个按键弹起的毫秒数 |
| lockShortcut | object | 锁定的快捷键信息 |
| cleanShortcut | object | 清空的快捷键信息 |

一些细节如下:

Expand All @@ -99,6 +100,8 @@ npm rebuild --runtime=electron --target=12.0.0 --disturl=https://atom.io/downloa

上述例子表示的快捷键即为 `Ctrl + Shift + L`。在使用快捷键锁定或者解锁键盘的时候将会收到系统通知。

**清空快捷键**:设置方法和锁定快捷键一样。在清空键盘后,所有的按键点击次数(包括热力图和总数)将会清零。

如果你使用默认设置,你将会得到一个亮色、无功能键盘。以下是暗色的配色方案:

```json
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ This is a json file including all the function switchers and style settings. Key
| antiMinimize | boolean | Automately restore while minimizing the keyboard |
| bounceTime | number | Milliseconds for a key to bounce up |
| lockShortcut | object | Information of lock shortcut |
| cleanShortcut | object | Information of clean shortcut |

Some details below:

Expand All @@ -99,6 +100,8 @@ Some details below:

The example above means `Ctrl + Shift + L`. If you use shortcut to lock / unlock the keyboard, you will receive a system message.

**Clean shortcut**: the setting types are the same as key shortcut. after cleaning the keyboard, all the key count (so as the key heatmap and total count) will be set as zero.

If you use default settings, you can get a light keyboard with no functions. Here is a color scheme for a dark keyboard:

```json
Expand Down
66 changes: 66 additions & 0 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

let useLockShortcut = false;
let lockShortcutInfo = {};
let useCleanShortcut = false;
let cleanShortcutInfo = {};

const keyIdMask = (x) => {
if(keyMaskList[x] !== undefined)
Expand Down Expand Up @@ -129,6 +131,21 @@
}
}

const cleanKeyboard = () => {
for(var i in keyCounter)
if(keyCounter.hasOwnProperty(i))
keyCounter[i] = 0;
currMaximum = 0;
if(keyHeatmap !== "none")
$(`.buttonDiv`).each(function(){
$(this).css("background", getColorFromPercent(0, keyHeatmap));
});
if(keyCount)
$(`.buttonDiv > .counter`).each(function(){
$(this).html(0);
});
}

let hitMatrix = {};
let hitTotal = 0;
let cpsCount = 0;
Expand Down Expand Up @@ -157,6 +174,24 @@
if(usage)
unlockKeyboard(false);
}
if(useCleanShortcut) {
var usage = true;
if(typeof e === "string"){
usage &= (false === cleanShortcutInfo.shiftKey);
usage &= (false === cleanShortcutInfo.altKey);
usage &= (false === cleanShortcutInfo.ctrlKey);
usage &= (false === cleanShortcutInfo.metaKey);
}
else{
usage &= (e.shiftKey === cleanShortcutInfo.shiftKey);
usage &= (e.altKey === cleanShortcutInfo.altKey);
usage &= (e.ctrlKey === cleanShortcutInfo.ctrlKey);
usage &= (e.metaKey === cleanShortcutInfo.metaKey);
}
usage &= (p === cleanShortcutInfo.id.toUpperCase());
if(usage)
cleanKeyboard();
}
return;
}
if(toolBarMode === "debug")
Expand Down Expand Up @@ -243,6 +278,24 @@
if(usage)
lockKeyboard(false);
}
if(useCleanShortcut) {
var usage = true;
if(typeof e === "string"){
usage &= (false === cleanShortcutInfo.shiftKey);
usage &= (false === cleanShortcutInfo.altKey);
usage &= (false === cleanShortcutInfo.ctrlKey);
usage &= (false === cleanShortcutInfo.metaKey);
}
else{
usage &= (e.shiftKey === cleanShortcutInfo.shiftKey);
usage &= (e.altKey === cleanShortcutInfo.altKey);
usage &= (e.ctrlKey === cleanShortcutInfo.ctrlKey);
usage &= (e.metaKey === cleanShortcutInfo.metaKey);
}
usage &= (p === cleanShortcutInfo.id.toUpperCase());
if(usage)
cleanKeyboard();
}
};
const keyupEvent = (e, wheel) => {
if(keyboardLocked)
Expand Down Expand Up @@ -455,6 +508,19 @@
useLockShortcut = true;
lockShortcutInfo = data.lockShortcut;
}
if(typeof data.cleanShortcut === "object" && !data.cleanShortcut.hasOwnProperty("length")){
if(typeof data.cleanShortcut.id !== "string"
|| typeof data.cleanShortcut.shiftKey !== "boolean"
|| typeof data.cleanShortcut.ctrlKey !== "boolean"
|| typeof data.cleanShortcut.altKey !== "boolean"
|| typeof data.cleanShortcut.metaKey !== "boolean"
){
setErrorMessage("Clean shortcut options not correct.");
return;
}
useCleanShortcut = true;
cleanShortcutInfo = data.cleanShortcut;
}
},
error: function(){
setErrorMessage("Cannot load options.");
Expand Down

0 comments on commit 724fb22

Please sign in to comment.