Merge pull request #61 from UltimateHackingKeyboard/fjozsef-redundant
Redundant KeystrokeAction behavior refactoring
This commit is contained in:
@@ -1,58 +0,0 @@
|
|||||||
import {UhkBuffer} from '../UhkBuffer';
|
|
||||||
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
|
|
||||||
import {assertUInt8, assertEnum} from '../assert';
|
|
||||||
|
|
||||||
enum LongPressAction {
|
|
||||||
leftCtrl,
|
|
||||||
leftShift,
|
|
||||||
leftAlt,
|
|
||||||
leftSuper,
|
|
||||||
rightCtrl,
|
|
||||||
rightShift,
|
|
||||||
rightAlt,
|
|
||||||
rightSuper,
|
|
||||||
mod,
|
|
||||||
fn,
|
|
||||||
mouse
|
|
||||||
}
|
|
||||||
|
|
||||||
export class DualRoleKeystrokeAction extends KeyAction {
|
|
||||||
|
|
||||||
@assertUInt8
|
|
||||||
scancode: number;
|
|
||||||
|
|
||||||
@assertEnum(LongPressAction)
|
|
||||||
private longPressAction: LongPressAction;
|
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): DualRoleKeystrokeAction {
|
|
||||||
this.assertKeyActionType(jsObject);
|
|
||||||
this.scancode = jsObject.scancode;
|
|
||||||
this.longPressAction = LongPressAction[<string> jsObject.longPressAction];
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
_fromBinary(buffer: UhkBuffer): DualRoleKeystrokeAction {
|
|
||||||
this.readAndAssertKeyActionId(buffer);
|
|
||||||
this.scancode = buffer.readUInt8();
|
|
||||||
this.longPressAction = buffer.readUInt8();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
_toJsObject(): any {
|
|
||||||
return {
|
|
||||||
keyActionType: keyActionType.DualRoleKeystrokeAction,
|
|
||||||
scancode: this.scancode,
|
|
||||||
longPressAction: LongPressAction[this.longPressAction]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
_toBinary(buffer: UhkBuffer): void {
|
|
||||||
buffer.writeUInt8(KeyActionId.DualRoleKeystrokeAction);
|
|
||||||
buffer.writeUInt8(this.scancode);
|
|
||||||
buffer.writeUInt8(this.longPressAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
toString(): string {
|
|
||||||
return `<DualRoleKeystrokeAction scancode="${this.scancode}" longPressAction="${this.longPressAction}">`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import {KeyModifiers} from './KeystrokeModifiersAction';
|
|
||||||
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
|
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
|
||||||
|
import {KeyModifiers} from './KeyModifiers';
|
||||||
import {UhkBuffer} from '../UhkBuffer';
|
import {UhkBuffer} from '../UhkBuffer';
|
||||||
import {assertUInt8} from '../assert';
|
import {assertUInt8} from '../assert';
|
||||||
|
|
||||||
|
|||||||
@@ -6,21 +6,23 @@ import {UhkBuffer} from '../UhkBuffer';
|
|||||||
export enum KeyActionId {
|
export enum KeyActionId {
|
||||||
NoneAction = 0,
|
NoneAction = 0,
|
||||||
KeystrokeAction = 1,
|
KeystrokeAction = 1,
|
||||||
KeystrokeModifiersAction = 2,
|
/*
|
||||||
KeystrokeWithModifiersAction = 3,
|
1 - 7 are reserved for KeystrokeAction
|
||||||
DualRoleKeystrokeAction = 4,
|
3 bits:
|
||||||
SwitchLayerAction = 5,
|
1: Do we have scancode?
|
||||||
SwitchKeymapAction = 6,
|
2: Do we have modifiers?
|
||||||
MouseAction = 7,
|
3: Do we have longpress?
|
||||||
PlayMacroAction = 8
|
*/
|
||||||
|
LastKeystrokeAction = 7, // TODO: remove this after refactoring the keyActionId check
|
||||||
|
SwitchLayerAction = 8,
|
||||||
|
SwitchKeymapAction = 9,
|
||||||
|
MouseAction = 10,
|
||||||
|
PlayMacroAction = 11
|
||||||
}
|
}
|
||||||
|
|
||||||
export let keyActionType = {
|
export let keyActionType = {
|
||||||
NoneAction : 'none',
|
NoneAction : 'none',
|
||||||
KeystrokeAction : 'keystroke',
|
KeystrokeAction : 'keystroke',
|
||||||
KeystrokeModifiersAction : 'keystrokeModifiers',
|
|
||||||
KeystrokeWithModifiersAction : 'keystrokeWithModifiers',
|
|
||||||
DualRoleKeystrokeAction : 'dualRoleKeystroke',
|
|
||||||
SwitchLayerAction : 'switchLayer',
|
SwitchLayerAction : 'switchLayer',
|
||||||
SwitchKeymapAction : 'switchKeymap',
|
SwitchKeymapAction : 'switchKeymap',
|
||||||
MouseAction : 'mouse',
|
MouseAction : 'mouse',
|
||||||
@@ -28,21 +30,27 @@ export let keyActionType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export abstract class KeyAction extends Serializable<KeyAction> {
|
export abstract class KeyAction extends Serializable<KeyAction> {
|
||||||
assertKeyActionType(jsObject: any) {
|
|
||||||
let keyActionClassname = this.constructor.name;
|
assertKeyActionType(jsObject: any): void {
|
||||||
let keyActionTypeString = keyActionType[keyActionClassname];
|
let keyActionClassname: string = this.constructor.name;
|
||||||
|
let keyActionTypeString: string = keyActionType[keyActionClassname];
|
||||||
if (jsObject.keyActionType !== keyActionTypeString) {
|
if (jsObject.keyActionType !== keyActionTypeString) {
|
||||||
throw `Invalid ${keyActionClassname}.keyActionType: ${jsObject.keyActionType}`;
|
throw `Invalid ${keyActionClassname}.keyActionType: ${jsObject.keyActionType}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
readAndAssertKeyActionId(buffer: UhkBuffer) {
|
readAndAssertKeyActionId(buffer: UhkBuffer): KeyActionId {
|
||||||
let classname = this.constructor.name;
|
let classname: string = this.constructor.name;
|
||||||
let readKeyActionId = buffer.readUInt8();
|
let readKeyActionId: number = buffer.readUInt8();
|
||||||
let keyActionId = KeyActionId[<string> classname];
|
let keyActionId: number = KeyActionId[classname];
|
||||||
if (readKeyActionId !== keyActionId) {
|
if (keyActionId === KeyActionId.KeystrokeAction) {
|
||||||
|
if (readKeyActionId < KeyActionId.KeystrokeAction || readKeyActionId > KeyActionId.LastKeystrokeAction) {
|
||||||
|
throw `Invalid ${classname} first byte: ${readKeyActionId}`;
|
||||||
|
}
|
||||||
|
} else if (readKeyActionId !== keyActionId) {
|
||||||
throw `Invalid ${classname} first byte: ${readKeyActionId}`;
|
throw `Invalid ${classname} first byte: ${readKeyActionId}`;
|
||||||
}
|
}
|
||||||
|
return readKeyActionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract _fromJsObject(jsObject: any): KeyAction;
|
abstract _fromJsObject(jsObject: any): KeyAction;
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
import {ClassArray} from '../ClassArray';
|
import {ClassArray} from '../ClassArray';
|
||||||
import {UhkBuffer} from '../UhkBuffer';
|
import {UhkBuffer} from '../UhkBuffer';
|
||||||
import {DualRoleKeystrokeAction} from './DualRoleKeystrokeAction';
|
|
||||||
import {NoneAction} from './NoneAction';
|
import {NoneAction} from './NoneAction';
|
||||||
import {KeystrokeAction} from './KeystrokeAction';
|
import {KeystrokeAction} from './KeystrokeAction';
|
||||||
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
|
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
|
||||||
import {KeystrokeModifiersAction} from './KeystrokeModifiersAction';
|
|
||||||
import {KeystrokeWithModifiersAction} from './KeystrokeWithModifiersAction';
|
|
||||||
import {SwitchLayerAction} from './SwitchLayerAction';
|
import {SwitchLayerAction} from './SwitchLayerAction';
|
||||||
import {SwitchKeymapAction} from './SwitchKeymapAction';
|
import {SwitchKeymapAction} from './SwitchKeymapAction';
|
||||||
import {MouseAction} from './MouseAction';
|
import {MouseAction} from './MouseAction';
|
||||||
@@ -19,12 +16,6 @@ export class KeyActions extends ClassArray<KeyAction> {
|
|||||||
return new NoneAction().fromJsObject(jsObject);
|
return new NoneAction().fromJsObject(jsObject);
|
||||||
case keyActionType.KeystrokeAction:
|
case keyActionType.KeystrokeAction:
|
||||||
return new KeystrokeAction().fromJsObject(jsObject);
|
return new KeystrokeAction().fromJsObject(jsObject);
|
||||||
case keyActionType.KeystrokeModifiersAction:
|
|
||||||
return new KeystrokeModifiersAction().fromJsObject(jsObject);
|
|
||||||
case keyActionType.KeystrokeWithModifiersAction:
|
|
||||||
return new KeystrokeWithModifiersAction().fromJsObject(jsObject);
|
|
||||||
case keyActionType.DualRoleKeystrokeAction:
|
|
||||||
return new DualRoleKeystrokeAction().fromJsObject(jsObject);
|
|
||||||
case keyActionType.SwitchLayerAction:
|
case keyActionType.SwitchLayerAction:
|
||||||
return new SwitchLayerAction().fromJsObject(jsObject);
|
return new SwitchLayerAction().fromJsObject(jsObject);
|
||||||
case keyActionType.SwitchKeymapAction:
|
case keyActionType.SwitchKeymapAction:
|
||||||
@@ -47,17 +38,13 @@ export class KeyActions extends ClassArray<KeyAction> {
|
|||||||
buffer.enableDump = false;
|
buffer.enableDump = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (keyActionFirstByte >= KeyActionId.KeystrokeAction && keyActionFirstByte < KeyActionId.LastKeystrokeAction) {
|
||||||
|
return new KeystrokeAction().fromBinary(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
switch (keyActionFirstByte) {
|
switch (keyActionFirstByte) {
|
||||||
case KeyActionId.NoneAction:
|
case KeyActionId.NoneAction:
|
||||||
return new NoneAction().fromBinary(buffer);
|
return new NoneAction().fromBinary(buffer);
|
||||||
case KeyActionId.KeystrokeAction:
|
|
||||||
return new KeystrokeAction().fromBinary(buffer);
|
|
||||||
case KeyActionId.KeystrokeModifiersAction:
|
|
||||||
return new KeystrokeModifiersAction().fromBinary(buffer);
|
|
||||||
case KeyActionId.KeystrokeWithModifiersAction:
|
|
||||||
return new KeystrokeWithModifiersAction().fromBinary(buffer);
|
|
||||||
case KeyActionId.DualRoleKeystrokeAction:
|
|
||||||
return new DualRoleKeystrokeAction().fromBinary(buffer);
|
|
||||||
case KeyActionId.SwitchLayerAction:
|
case KeyActionId.SwitchLayerAction:
|
||||||
return new SwitchLayerAction().fromBinary(buffer);
|
return new SwitchLayerAction().fromBinary(buffer);
|
||||||
case KeyActionId.SwitchKeymapAction:
|
case KeyActionId.SwitchKeymapAction:
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
export enum KeyModifiers {
|
||||||
|
leftCtrl = 1 << 0,
|
||||||
|
leftShift = 1 << 1,
|
||||||
|
leftAlt = 1 << 2,
|
||||||
|
leftGui = 1 << 3,
|
||||||
|
rightCtrl = 1 << 4,
|
||||||
|
rightShift = 1 << 5,
|
||||||
|
rightAlt = 1 << 6,
|
||||||
|
rightGui = 1 << 7
|
||||||
|
}
|
||||||
@@ -1,37 +1,133 @@
|
|||||||
import {UhkBuffer} from '../UhkBuffer';
|
import {UhkBuffer} from '../UhkBuffer';
|
||||||
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
|
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
|
||||||
import {assertUInt8} from '../assert';
|
import {KeyModifiers} from './KeyModifiers';
|
||||||
|
import {assertUInt8, assertEnum} from '../assert';
|
||||||
|
import {LongPressAction} from './LongPressAction';
|
||||||
|
|
||||||
|
export enum KeystrokeActionFlag {
|
||||||
|
scancode = 1 << 0,
|
||||||
|
modifierMask = 1 << 1,
|
||||||
|
longPressAction = 1 << 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
interface JsObjectKeystrokeAction {
|
||||||
|
keyActionType: string;
|
||||||
|
scancode?: number;
|
||||||
|
modifierMask?: number;
|
||||||
|
longPressAction?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class KeystrokeAction extends KeyAction {
|
export class KeystrokeAction extends KeyAction {
|
||||||
|
|
||||||
@assertUInt8
|
@assertUInt8
|
||||||
scancode: number;
|
scancode: number;
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): KeystrokeAction {
|
@assertUInt8
|
||||||
|
modifierMask: number;
|
||||||
|
|
||||||
|
@assertEnum(LongPressAction)
|
||||||
|
longPressAction: LongPressAction;
|
||||||
|
|
||||||
|
_fromJsObject(jsObject: JsObjectKeystrokeAction): KeystrokeAction {
|
||||||
this.assertKeyActionType(jsObject);
|
this.assertKeyActionType(jsObject);
|
||||||
this.scancode = jsObject.scancode;
|
this.scancode = jsObject.scancode;
|
||||||
|
this.modifierMask = jsObject.modifierMask;
|
||||||
|
this.longPressAction = LongPressAction[jsObject.longPressAction];
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
_fromBinary(buffer: UhkBuffer): KeystrokeAction {
|
_fromBinary(buffer: UhkBuffer): KeystrokeAction {
|
||||||
this.readAndAssertKeyActionId(buffer);
|
let keyActionId: KeyActionId = this.readAndAssertKeyActionId(buffer);
|
||||||
this.scancode = buffer.readUInt8();
|
let flags: number = keyActionId - KeyActionId.KeystrokeAction;
|
||||||
|
if (flags & KeystrokeActionFlag.scancode) {
|
||||||
|
this.scancode = buffer.readUInt8();
|
||||||
|
}
|
||||||
|
if (flags & KeystrokeActionFlag.modifierMask) {
|
||||||
|
this.modifierMask = buffer.readUInt8();
|
||||||
|
}
|
||||||
|
if (flags & KeystrokeActionFlag.longPressAction) {
|
||||||
|
this.longPressAction = buffer.readUInt8();
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
_toJsObject(): any {
|
_toJsObject(): JsObjectKeystrokeAction {
|
||||||
return {
|
let jsObject: JsObjectKeystrokeAction = {
|
||||||
keyActionType: keyActionType.KeystrokeAction,
|
keyActionType: keyActionType.KeystrokeAction
|
||||||
scancode: this.scancode
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (this.hasScancode()) {
|
||||||
|
jsObject.scancode = this.scancode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.hasActiveModifier()) {
|
||||||
|
jsObject.modifierMask = this.modifierMask;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.hasLongPressAction()) {
|
||||||
|
jsObject.longPressAction = LongPressAction[this.longPressAction];
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
_toBinary(buffer: UhkBuffer) {
|
_toBinary(buffer: UhkBuffer) {
|
||||||
buffer.writeUInt8(KeyActionId.KeystrokeAction);
|
let flags = 0;
|
||||||
buffer.writeUInt8(this.scancode);
|
let bufferData: number[] = [];
|
||||||
|
|
||||||
|
if (this.hasScancode()) {
|
||||||
|
flags |= KeystrokeActionFlag.scancode;
|
||||||
|
bufferData.push(this.scancode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.hasActiveModifier()) {
|
||||||
|
flags |= KeystrokeActionFlag.modifierMask;
|
||||||
|
bufferData.push(this.modifierMask);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.hasLongPressAction()) {
|
||||||
|
flags |= KeystrokeActionFlag.longPressAction;
|
||||||
|
bufferData.push(this.longPressAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.writeUInt8(KeyActionId.KeystrokeAction + flags);
|
||||||
|
for (let i = 0; i < bufferData.length; ++i) {
|
||||||
|
buffer.writeUInt8(bufferData[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string {
|
||||||
return `<KeystrokeAction scancode="${this.scancode}">`;
|
let properties: string[] = [];
|
||||||
|
if (this.hasScancode()) {
|
||||||
|
properties.push(`scancode="${this.scancode}"`);
|
||||||
|
}
|
||||||
|
if (this.hasActiveModifier()) {
|
||||||
|
properties.push(`modifierMask="${this.modifierMask}"`);
|
||||||
|
}
|
||||||
|
if (this.hasLongPressAction()) {
|
||||||
|
properties.push(`longPressAction="${this.longPressAction}"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return `<KeystrokeAction ${properties.join(' ')}>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
isActive(modifier: KeyModifiers): boolean {
|
||||||
|
return (this.modifierMask & modifier) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
hasActiveModifier(): boolean {
|
||||||
|
return this.modifierMask > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
hasLongPressAction(): boolean {
|
||||||
|
return this.longPressAction !== undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
hasScancode(): boolean {
|
||||||
|
return !!this.scancode;
|
||||||
|
}
|
||||||
|
|
||||||
|
hasOnlyOneActiveModifier(): boolean {
|
||||||
|
return this.modifierMask !== 0 && !(this.modifierMask & this.modifierMask - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
import {UhkBuffer} from '../UhkBuffer';
|
|
||||||
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
|
|
||||||
import {assertUInt8} from '../assert';
|
|
||||||
|
|
||||||
export enum KeyModifiers {
|
|
||||||
leftCtrl = 1 << 0,
|
|
||||||
leftShift = 1 << 1,
|
|
||||||
leftAlt = 1 << 2,
|
|
||||||
leftGui = 1 << 3,
|
|
||||||
rightCtrl = 1 << 4,
|
|
||||||
rightShift = 1 << 5,
|
|
||||||
rightAlt = 1 << 6,
|
|
||||||
rightGui = 1 << 7
|
|
||||||
}
|
|
||||||
|
|
||||||
export class KeystrokeModifiersAction extends KeyAction {
|
|
||||||
|
|
||||||
@assertUInt8
|
|
||||||
modifierMask: number;
|
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): KeystrokeModifiersAction {
|
|
||||||
this.assertKeyActionType(jsObject);
|
|
||||||
this.modifierMask = jsObject.modifierMask;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
_fromBinary(buffer: UhkBuffer): KeystrokeModifiersAction {
|
|
||||||
this.readAndAssertKeyActionId(buffer);
|
|
||||||
this.modifierMask = buffer.readUInt8();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
_toJsObject(): any {
|
|
||||||
return {
|
|
||||||
keyActionType: keyActionType.KeystrokeModifiersAction,
|
|
||||||
modifierMask: this.modifierMask
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
_toBinary(buffer: UhkBuffer) {
|
|
||||||
buffer.writeUInt8(KeyActionId.KeystrokeModifiersAction);
|
|
||||||
buffer.writeUInt8(this.modifierMask);
|
|
||||||
}
|
|
||||||
|
|
||||||
toString(): string {
|
|
||||||
return `<KeystrokeModifiersAction modifierMask="${this.modifierMask}">`;
|
|
||||||
}
|
|
||||||
|
|
||||||
isModifierActive(modifier: KeyModifiers): boolean {
|
|
||||||
return (this.modifierMask & modifier) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
isOnlyOneModifierActive(): boolean {
|
|
||||||
return this.modifierMask !== 0 && !(this.modifierMask & this.modifierMask - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
import {UhkBuffer} from '../UhkBuffer';
|
|
||||||
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
|
|
||||||
import {KeyModifiers} from './KeystrokeModifiersAction';
|
|
||||||
import {assertUInt8} from '../assert';
|
|
||||||
|
|
||||||
export class KeystrokeWithModifiersAction extends KeyAction {
|
|
||||||
|
|
||||||
@assertUInt8
|
|
||||||
modifierMask: number;
|
|
||||||
|
|
||||||
@assertUInt8
|
|
||||||
scancode: number;
|
|
||||||
|
|
||||||
_fromJsObject(jsObject: any): KeystrokeWithModifiersAction {
|
|
||||||
this.assertKeyActionType(jsObject);
|
|
||||||
this.scancode = jsObject.scancode;
|
|
||||||
this.modifierMask = jsObject.modifierMask;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
_fromBinary(buffer: UhkBuffer): KeystrokeWithModifiersAction {
|
|
||||||
this.readAndAssertKeyActionId(buffer);
|
|
||||||
this.scancode = buffer.readUInt8();
|
|
||||||
this.modifierMask = buffer.readUInt8();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
_toJsObject(): any {
|
|
||||||
return {
|
|
||||||
keyActionType: keyActionType.KeystrokeWithModifiersAction,
|
|
||||||
scancode: this.scancode,
|
|
||||||
modifierMask: this.modifierMask
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
_toBinary(buffer: UhkBuffer) {
|
|
||||||
buffer.writeUInt8(KeyActionId.KeystrokeWithModifiersAction);
|
|
||||||
buffer.writeUInt8(this.scancode);
|
|
||||||
buffer.writeUInt8(this.modifierMask);
|
|
||||||
}
|
|
||||||
|
|
||||||
toString(): string {
|
|
||||||
return `<KeystrokeWithModifiersAction scancode="${this.scancode}" modifierMask="${this.modifierMask}">`;
|
|
||||||
}
|
|
||||||
|
|
||||||
isModifierActive(modifier: KeyModifiers): boolean {
|
|
||||||
return (this.modifierMask & modifier) > 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
export enum LongPressAction {
|
||||||
|
leftCtrl,
|
||||||
|
leftShift,
|
||||||
|
leftAlt,
|
||||||
|
leftSuper,
|
||||||
|
rightCtrl,
|
||||||
|
rightShift,
|
||||||
|
rightAlt,
|
||||||
|
rightSuper,
|
||||||
|
mod,
|
||||||
|
fn,
|
||||||
|
mouse
|
||||||
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import {KeyModifiers} from './KeystrokeModifiersAction';
|
|
||||||
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
|
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
|
||||||
|
import {KeyModifiers} from './KeyModifiers';
|
||||||
import {UhkBuffer} from '../UhkBuffer';
|
import {UhkBuffer} from '../UhkBuffer';
|
||||||
import {assertUInt8} from '../assert';
|
import {assertUInt8} from '../assert';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {KeyModifiers} from './KeystrokeModifiersAction';
|
|
||||||
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
|
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
|
||||||
|
import {KeyModifiers} from './KeyModifiers';
|
||||||
import {UhkBuffer} from '../UhkBuffer';
|
import {UhkBuffer} from '../UhkBuffer';
|
||||||
import {assertUInt8} from '../assert';
|
import {assertUInt8} from '../assert';
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,6 @@
|
|||||||
"enum": [
|
"enum": [
|
||||||
"none",
|
"none",
|
||||||
"keystroke",
|
"keystroke",
|
||||||
"keystrokeModifiers",
|
|
||||||
"switchLayer",
|
"switchLayer",
|
||||||
"switchKeymap",
|
"switchKeymap",
|
||||||
"playMacro",
|
"playMacro",
|
||||||
|
|||||||
@@ -134,7 +134,7 @@
|
|||||||
"scancode": 56
|
"scancode": 56
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 32
|
"modifierMask": 32
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -147,15 +147,15 @@
|
|||||||
"toggle": false
|
"toggle": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 64
|
"modifierMask": 64
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 128
|
"modifierMask": 128
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 16
|
"modifierMask": 16
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -247,7 +247,7 @@
|
|||||||
"scancode": 10
|
"scancode": 10
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 2
|
"modifierMask": 2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -271,15 +271,15 @@
|
|||||||
"scancode": 5
|
"scancode": 5
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 1
|
"modifierMask": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 8
|
"modifierMask": 8
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 4
|
"modifierMask": 4
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -403,7 +403,7 @@
|
|||||||
"scancode": 118
|
"scancode": 118
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 32
|
"modifierMask": 32
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -415,15 +415,15 @@
|
|||||||
"toggle": false
|
"toggle": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 64
|
"modifierMask": 64
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 128
|
"modifierMask": 128
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 16
|
"modifierMask": 16
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -497,7 +497,7 @@
|
|||||||
"keyActionType": "none"
|
"keyActionType": "none"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 2
|
"modifierMask": 2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -516,15 +516,15 @@
|
|||||||
"keyActionType": "none"
|
"keyActionType": "none"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 1
|
"modifierMask": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 8
|
"modifierMask": 8
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 4
|
"modifierMask": 4
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -641,7 +641,7 @@
|
|||||||
"keyActionType": "none"
|
"keyActionType": "none"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 32
|
"modifierMask": 32
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -653,15 +653,15 @@
|
|||||||
"toggle": false
|
"toggle": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 64
|
"modifierMask": 64
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 128
|
"modifierMask": 128
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 16
|
"modifierMask": 16
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -739,7 +739,7 @@
|
|||||||
"keyActionType": "none"
|
"keyActionType": "none"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 2
|
"modifierMask": 2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -758,15 +758,15 @@
|
|||||||
"keyActionType": "none"
|
"keyActionType": "none"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 1
|
"modifierMask": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 8
|
"modifierMask": 8
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keyActionType": "keystrokeModifiers",
|
"keyActionType": "keystroke",
|
||||||
"modifierMask": 4
|
"modifierMask": 4
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {NgSwitch, NgSwitchWhen} from '@angular/common';
|
|||||||
|
|
||||||
import {KeyAction} from '../../../config-serializer/config-items/KeyAction';
|
import {KeyAction} from '../../../config-serializer/config-items/KeyAction';
|
||||||
import {KeystrokeAction} from '../../../config-serializer/config-items/KeystrokeAction';
|
import {KeystrokeAction} from '../../../config-serializer/config-items/KeystrokeAction';
|
||||||
import {KeystrokeModifiersAction, KeyModifiers} from '../../../config-serializer/config-items/KeystrokeModifiersAction';
|
import {KeyModifiers} from '../../../config-serializer/config-items/KeyModifiers';
|
||||||
import {SwitchLayerAction, LayerName} from '../../../config-serializer/config-items/SwitchLayerAction';
|
import {SwitchLayerAction, LayerName} from '../../../config-serializer/config-items/SwitchLayerAction';
|
||||||
import {MapperService} from '../../services/mapper.service';
|
import {MapperService} from '../../services/mapper.service';
|
||||||
import {SwitchKeymapAction} from '../../../config-serializer/config-items/SwitchKeymapAction';
|
import {SwitchKeymapAction} from '../../../config-serializer/config-items/SwitchKeymapAction';
|
||||||
@@ -115,10 +115,27 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges {
|
|||||||
|
|
||||||
this.labelType = LabelTypes.OneLineText;
|
this.labelType = LabelTypes.OneLineText;
|
||||||
|
|
||||||
if (this.keyAction instanceof KeystrokeModifiersAction) {
|
if (this.keyAction instanceof KeystrokeAction) {
|
||||||
let keyAction: KeystrokeModifiersAction = this.keyAction as KeystrokeModifiersAction;
|
let keyAction: KeystrokeAction = this.keyAction as KeystrokeAction;
|
||||||
let newLabelSource: string[] = [];
|
let newLabelSource: string[];
|
||||||
if (keyAction.isOnlyOneModifierActive()) {
|
|
||||||
|
if (keyAction.hasScancode()) {
|
||||||
|
let scancode: number = keyAction.scancode;
|
||||||
|
newLabelSource = this.mapperService.scanCodeToText(scancode);
|
||||||
|
if (newLabelSource) {
|
||||||
|
if (newLabelSource.length === 1) {
|
||||||
|
this.labelSource = newLabelSource[0];
|
||||||
|
this.labelType = LabelTypes.OneLineText;
|
||||||
|
} else {
|
||||||
|
this.labelSource = newLabelSource;
|
||||||
|
this.labelType = LabelTypes.TwoLineText;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.labelSource = this.mapperService.scanCodeToSvgImagePath(scancode);
|
||||||
|
this.labelType = LabelTypes.SingleIcon;
|
||||||
|
}
|
||||||
|
} else if (keyAction.hasOnlyOneActiveModifier()) {
|
||||||
|
newLabelSource = [];
|
||||||
switch (keyAction.modifierMask) {
|
switch (keyAction.modifierMask) {
|
||||||
case KeyModifiers.leftCtrl:
|
case KeyModifiers.leftCtrl:
|
||||||
case KeyModifiers.rightCtrl:
|
case KeyModifiers.rightCtrl:
|
||||||
@@ -140,22 +157,7 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges {
|
|||||||
newLabelSource.push('Undefined');
|
newLabelSource.push('Undefined');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
this.labelSource = newLabelSource;
|
||||||
this.labelSource = newLabelSource;
|
|
||||||
} else if (this.keyAction instanceof KeystrokeAction) {
|
|
||||||
let scancode: number = (this.keyAction as KeystrokeAction).scancode;
|
|
||||||
let newLabelSource: string[] = this.mapperService.scanCodeToText(scancode);
|
|
||||||
if (newLabelSource) {
|
|
||||||
if (newLabelSource.length === 1) {
|
|
||||||
this.labelSource = newLabelSource[0];
|
|
||||||
this.labelType = LabelTypes.OneLineText;
|
|
||||||
} else {
|
|
||||||
this.labelSource = newLabelSource;
|
|
||||||
this.labelType = LabelTypes.TwoLineText;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.labelSource = this.mapperService.scanCodeToSvgImagePath(scancode);
|
|
||||||
this.labelType = LabelTypes.SingleIcon;
|
|
||||||
}
|
}
|
||||||
} else if (this.keyAction instanceof SwitchLayerAction) {
|
} else if (this.keyAction instanceof SwitchLayerAction) {
|
||||||
let keyAction: SwitchLayerAction = this.keyAction as SwitchLayerAction;
|
let keyAction: SwitchLayerAction = this.keyAction as SwitchLayerAction;
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import { CaptureKeystrokeButtonComponent } from '../widgets/capture-keystroke-bu
|
|||||||
|
|
||||||
import { KeyAction } from '../../../../config-serializer/config-items/KeyAction';
|
import { KeyAction } from '../../../../config-serializer/config-items/KeyAction';
|
||||||
import { KeystrokeAction } from '../../../../config-serializer/config-items/KeystrokeAction';
|
import { KeystrokeAction } from '../../../../config-serializer/config-items/KeystrokeAction';
|
||||||
import { KeystrokeModifiersAction } from '../../../../config-serializer/config-items/KeystrokeModifiersAction';
|
|
||||||
import { KeystrokeWithModifiersAction } from '../../../../config-serializer/config-items/KeystrokeWithModifiersAction';
|
|
||||||
import { KeyActionSaver } from '../key-action-saver';
|
import { KeyActionSaver } from '../key-action-saver';
|
||||||
|
|
||||||
import {IconComponent} from '../widgets/icon.component';
|
import {IconComponent} from '../widgets/icon.component';
|
||||||
@@ -66,8 +64,8 @@ export class KeypressTabComponent implements OnInit, KeyActionSaver {
|
|||||||
|
|
||||||
ngOnInit() { }
|
ngOnInit() { }
|
||||||
|
|
||||||
getKeyAction(): KeystrokeAction | KeystrokeModifiersAction | KeystrokeWithModifiersAction {
|
getKeyAction(): KeystrokeAction {
|
||||||
return;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
keyActionValid(): boolean {
|
keyActionValid(): boolean {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {TextMacroAction} from '../../../../config-serializer/config-items/TextMa
|
|||||||
|
|
||||||
import {IconComponent} from '../widgets/icon.component';
|
import {IconComponent} from '../widgets/icon.component';
|
||||||
|
|
||||||
import {KeyModifiers} from '../../../../config-serializer/config-items/KeystrokeModifiersAction';
|
import {KeyModifiers} from '../../../../config-serializer/config-items/KeyModifiers';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user