From 3ae8c3eb4b3eda23c1c2dfd63e6279a7479b7d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Mon, 4 Apr 2016 02:51:09 +0200 Subject: [PATCH] Add KeystrokeModifiersAction. --- config-serializer/UhkBuffer.ts | 2 +- config-serializer/config-items/KeyAction.ts | 14 ++++---- config-serializer/config-items/KeyActions.ts | 9 +++++ .../config-items/KeystrokeModifiersAction.ts | 33 +++++++++++++++++++ .../KeystrokeWithModifiersAction.ts | 6 ++-- .../config-items/config-items.ts | 1 + config-serializer/uhk-config.json | 4 +++ 7 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 config-serializer/config-items/KeystrokeModifiersAction.ts diff --git a/config-serializer/UhkBuffer.ts b/config-serializer/UhkBuffer.ts index 6541af73..9b6722dd 100644 --- a/config-serializer/UhkBuffer.ts +++ b/config-serializer/UhkBuffer.ts @@ -41,9 +41,9 @@ class UhkBuffer { } writeUInt8(value: number): void { + this.dump(`u8(${value})`); this.buffer.writeUInt8(value, this.offset); this.offset += 1; - this.dump(`u8(${value})`); } readInt16(): number { diff --git a/config-serializer/config-items/KeyAction.ts b/config-serializer/config-items/KeyAction.ts index 7f1e1fc0..a369f4ae 100644 --- a/config-serializer/config-items/KeyAction.ts +++ b/config-serializer/config-items/KeyAction.ts @@ -4,17 +4,19 @@ enum KeyActionId { NoneAction = 0, KeystrokeAction = 1, - KeystrokeWithModifiersAction = 2, - DualRoleKeystrokeAction = 3, - SwitchLayerAction = 4, - SwitchKeymapAction = 5, - MouseAction = 6, - PlayMacroAction = 7 + KeystrokeModifiersAction = 2, + KeystrokeWithModifiersAction = 3, + DualRoleKeystrokeAction = 4, + SwitchLayerAction = 5, + SwitchKeymapAction = 6, + MouseAction = 7, + PlayMacroAction = 8 } let KeyActionType = { NoneAction : 'none', KeystrokeAction : 'keystroke', + KeystrokeModifiersAction : 'keystrokeModifiers', KeystrokeWithModifiersAction : 'keystrokeWithModifiers', DualRoleKeystrokeAction : 'dualRoleKeystroke', SwitchLayerAction : 'switchLayer', diff --git a/config-serializer/config-items/KeyActions.ts b/config-serializer/config-items/KeyActions.ts index 91f75d49..4848ae26 100644 --- a/config-serializer/config-items/KeyActions.ts +++ b/config-serializer/config-items/KeyActions.ts @@ -6,6 +6,8 @@ class KeyActions extends ClassArray { return new NoneAction().fromJsObject(jsObject); case KeyActionType.KeystrokeAction: return new KeystrokeAction().fromJsObject(jsObject); + case KeyActionType.KeystrokeModifiersAction: + return new KeystrokeModifiersAction().fromJsObject(jsObject); case KeyActionType.KeystrokeWithModifiersAction: return new KeystrokeWithModifiersAction().fromJsObject(jsObject); case KeyActionType.DualRoleKeystrokeAction: @@ -27,11 +29,18 @@ class KeyActions extends ClassArray { let keyActionFirstByte = buffer.readUInt8(); buffer.backtrack(); + if (buffer.enableDump) { + process.stdout.write(']\n'); + buffer.enableDump = false; + } + switch (keyActionFirstByte) { case KeyActionId.NoneAction: 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: diff --git a/config-serializer/config-items/KeystrokeModifiersAction.ts b/config-serializer/config-items/KeystrokeModifiersAction.ts new file mode 100644 index 00000000..971cf5c6 --- /dev/null +++ b/config-serializer/config-items/KeystrokeModifiersAction.ts @@ -0,0 +1,33 @@ +class KeystrokeModifiersAction extends KeyAction { + + modifierMask: number; + + _fromJsObject(jsObject: any): KeystrokeModifiersAction { + this.assertKeyActionType( + jsObject, KeyActionType.KeystrokeModifiersAction, 'KeystrokeModifiersAction'); + this.modifierMask = jsObject.modifierMask; + return this; + } + + _fromBinary(buffer: UhkBuffer): KeystrokeModifiersAction { + this.readAndAssertKeyActionId(buffer, KeyActionId.KeystrokeModifiersAction, 'KeystrokeModifiersAction'); + 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 ``; + } +} diff --git a/config-serializer/config-items/KeystrokeWithModifiersAction.ts b/config-serializer/config-items/KeystrokeWithModifiersAction.ts index 646b8eee..c62b2a3b 100644 --- a/config-serializer/config-items/KeystrokeWithModifiersAction.ts +++ b/config-serializer/config-items/KeystrokeWithModifiersAction.ts @@ -1,7 +1,5 @@ class KeystrokeWithModifiersAction extends KeyAction { - static keyActionTypeString = 'keystrokeWithModifiers'; - modifierMask: number; private _scancode: number; @@ -19,7 +17,7 @@ class KeystrokeWithModifiersAction extends KeyAction { _fromJsObject(jsObject: any): KeystrokeWithModifiersAction { this.assertKeyActionType( - jsObject, KeystrokeWithModifiersAction.keyActionTypeString, 'KeystrokeWithModifiersAction'); + jsObject, KeyActionType.KeystrokeWithModifiersAction, 'KeystrokeWithModifiersAction'); this.scancode = jsObject.scancode; this.modifierMask = jsObject.modifierMask; return this; @@ -34,7 +32,7 @@ class KeystrokeWithModifiersAction extends KeyAction { _toJsObject(): any { return { - keyActionType: KeystrokeWithModifiersAction.keyActionTypeString, + keyActionType: KeyActionType.KeystrokeWithModifiersAction, scancode: this.scancode, modifierMask: this.modifierMask }; diff --git a/config-serializer/config-items/config-items.ts b/config-serializer/config-items/config-items.ts index f9d47ebe..190b9a11 100644 --- a/config-serializer/config-items/config-items.ts +++ b/config-serializer/config-items/config-items.ts @@ -2,6 +2,7 @@ /// /// /// +/// /// /// /// diff --git a/config-serializer/uhk-config.json b/config-serializer/uhk-config.json index 0a496500..63a0d1c0 100644 --- a/config-serializer/uhk-config.json +++ b/config-serializer/uhk-config.json @@ -34,6 +34,10 @@ "keyActionType": "keystroke", "scancode": 110 }, + { + "keyActionType": "keystrokeModifiers", + "modifierMask":33 + }, { "keyActionType": "keystrokeWithModifiers", "scancode": 120,