added opposite shift "keymap" closes #1199

This commit is contained in:
Jack 2021-10-20 16:03:55 +01:00
parent 1f122399d5
commit c0ac8162a3
4 changed files with 94 additions and 11 deletions

View file

@ -606,6 +606,15 @@ let commandsOppositeShiftMode = {
TestUI.updateModesNotice();
},
},
{
id: "setOppositeShiftModeOn",
display: "keymap",
configValue: "keymap",
exec: () => {
UpdateConfig.setOppositeShiftMode("keymap");
TestUI.updateModesNotice();
},
},
],
};

View file

@ -727,7 +727,7 @@ $(document).keydown((event) => {
).toggleClass("dead");
}
if (Config.oppositeShiftMode === "on") {
if (Config.oppositeShiftMode !== "off") {
correctShiftUsed = ShiftTracker.isUsingOppositeShift(event) !== false;
}

View file

@ -1,6 +1,49 @@
import Config from "./config";
import Layouts from "./layouts";
export let leftState = false;
export let rightState = false;
let keymapStrings = {
left: null,
right: null,
keymap: null,
};
function buildKeymapStrings() {
if (keymapStrings.keymap === Config.keymapLayout) return;
let layout = Layouts[Config.keymapLayout]?.keys;
if (!layout) {
keymapStrings = {
left: null,
right: null,
keymap: Config.keymapLayout,
};
} else {
keymapStrings.left = (
layout.slice(0, 7).join(" ") +
" " +
layout.slice(13, 18).join(" ") +
" " +
layout.slice(26, 31).join(" ") +
" " +
layout.slice(38, 42).join(" ")
).replace(/ /g, "");
keymapStrings.right = (
layout.slice(7, 13).join(" ") +
" " +
layout.slice(19, 26).join(" ") +
" " +
layout.slice(31, 38).join(" ") +
" " +
layout.slice(43, 48).join(" ")
).replace(/ /g, "");
keymapStrings.keymap = Config.keymapLayout;
}
}
$(document).keydown((e) => {
if (e.code === "ShiftLeft") {
leftState = true;
@ -80,15 +123,34 @@ let rightSideKeys = [
export function isUsingOppositeShift(event) {
if (!leftState && !rightState) return null;
if (!rightSideKeys.includes(event.code) && !leftSideKeys.includes(event.code))
return null;
if (
(leftState && rightSideKeys.includes(event.code)) ||
(rightState && leftSideKeys.includes(event.code))
) {
return true;
} else {
return false;
if (Config.oppositeShiftMode === "on") {
if (
!rightSideKeys.includes(event.code) &&
!leftSideKeys.includes(event.code)
)
return null;
if (
(leftState && rightSideKeys.includes(event.code)) ||
(rightState && leftSideKeys.includes(event.code))
) {
return true;
} else {
return false;
}
} else if (Config.oppositeShiftMode === "keymap") {
buildKeymapStrings();
if (!keymapStrings.left || !keymapStrings.right) return null;
if (
(leftState && keymapStrings.right.includes(event.key)) ||
(rightState && keymapStrings.left.includes(event.key))
) {
return true;
} else {
return false;
}
}
}

View file

@ -2351,7 +2351,11 @@
<key>Y</key>
, and
<key>^</key>
because many people use the other hand for those keys.
because many people use the other hand for those keys. If
you're using external software to emulate your layout
(including QMK), you should use the "keymap" mode - the
standard "on" will not work. This will enforce opposite shift
based on the "keymap layout" setting.
</div>
<div class="buttons">
<div
@ -2370,6 +2374,14 @@
>
on
</div>
<div
class="button"
oppositeShiftMode="keymap"
tabindex="0"
onclick="this.blur();"
>
keymap
</div>
</div>
</div>
<div class="section stopOnError">