Fix menu scancode. (#586)

* Fix menu scancode.

* Change the old menu key scancode 118 to 101.

* validate scancodes
This commit is contained in:
László Monda
2018-03-11 22:56:12 +01:00
committed by GitHub
parent e84dbf2c15
commit e8fe0f8d3e
12 changed files with 261 additions and 18 deletions

View File

@@ -9,3 +9,6 @@ export * from './macro';
export * from './module';
export * from './module-configuration';
export * from './user-configuration';
export const SCANCODES = require('./scancodes.json');
export const SECONDARY_ROLES = require('./secondaryRole.json');

View File

@@ -8,6 +8,7 @@ import { SwitchKeymapAction, UnresolvedSwitchKeymapAction } from './switch-keyma
import { MouseAction } from './mouse-action';
import { PlayMacroAction } from './play-macro-action';
import { NoneAction } from './none-action';
import { isScancodeExists } from '../scancode-checker';
export class Helper {
@@ -26,7 +27,12 @@ export class Helper {
buffer.backtrack();
if (keyActionFirstByte >= KeyActionId.KeystrokeAction && keyActionFirstByte < KeyActionId.LastKeystrokeAction) {
return new KeystrokeAction().fromBinary(buffer);
const keystrokeAction = new KeystrokeAction().fromBinary(buffer);
if (isValidKeystrokeAction(keystrokeAction)) {
return keystrokeAction;
}
return new NoneAction();
}
switch (keyActionFirstByte) {
@@ -68,8 +74,14 @@ export class Helper {
}
switch (keyAction.keyActionType) {
case keyActionType.KeystrokeAction:
return new KeystrokeAction().fromJsonObject(keyAction);
case keyActionType.KeystrokeAction: {
const keystrokeAction = new KeystrokeAction().fromJsonObject(keyAction);
if (isValidKeystrokeAction(keystrokeAction)) {
return keystrokeAction;
}
return new NoneAction();
}
case keyActionType.SwitchLayerAction:
return new SwitchLayerAction().fromJsonObject(keyAction);
case keyActionType.SwitchKeymapAction:
@@ -85,3 +97,9 @@ export class Helper {
}
}
}
function isValidKeystrokeAction(keystrokeAction: KeystrokeAction): boolean {
return keystrokeAction.hasSecondaryRoleAction() ||
keystrokeAction.hasActiveModifier() ||
keystrokeAction.hasScancode() && isScancodeExists(keystrokeAction.scancode);
}

View File

@@ -0,0 +1,26 @@
import { SCANCODES } from './';
let scancodeMap: Map<number, any>;
export function isScancodeExists(scancode: number): boolean {
if (!scancodeMap) {
fillScancodeMap();
}
return scancodeMap.has(scancode);
}
function fillScancodeMap(): void {
scancodeMap = new Map<number, any>();
for (const scanGroup of SCANCODES) {
for (const child of scanGroup.children) {
if (child.additional && child.additional.scancode) {
scancodeMap.set(child.additional.scancode, child);
}
else {
scancodeMap.set(Number.parseInt(child.id), child);
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,60 @@
[
{
"id": "-1",
"text": "None"
},
{
"text": "Layer switcher",
"children": [
{
"id": "8",
"text": "Mod"
},
{
"id": "9",
"text": "Fn"
},
{
"id": "10",
"text": "Mouse"
}
]
},
{
"text": "Modifier",
"children": [
{
"id": "0",
"text": "LShift"
},
{
"id": "1",
"text": "LCtrl"
},
{
"id": "2",
"text": "LSuper"
},
{
"id": "3",
"text": "LAlt"
},
{
"id": "4",
"text": "RShift"
},
{
"id": "5",
"text": "RCtrl"
},
{
"id": "6",
"text": "RSuper"
},
{
"id": "7",
"text": "RAlt"
}
]
}
]