Add KeystrokeModifiersAction.

This commit is contained in:
László Monda
2016-04-04 02:51:09 +02:00
parent aac65cca2e
commit 3ae8c3eb4b
7 changed files with 58 additions and 11 deletions

View File

@@ -41,9 +41,9 @@ class UhkBuffer {
} }
writeUInt8(value: number): void { writeUInt8(value: number): void {
this.dump(`u8(${value})`);
this.buffer.writeUInt8(value, this.offset); this.buffer.writeUInt8(value, this.offset);
this.offset += 1; this.offset += 1;
this.dump(`u8(${value})`);
} }
readInt16(): number { readInt16(): number {

View File

@@ -4,17 +4,19 @@
enum KeyActionId { enum KeyActionId {
NoneAction = 0, NoneAction = 0,
KeystrokeAction = 1, KeystrokeAction = 1,
KeystrokeWithModifiersAction = 2, KeystrokeModifiersAction = 2,
DualRoleKeystrokeAction = 3, KeystrokeWithModifiersAction = 3,
SwitchLayerAction = 4, DualRoleKeystrokeAction = 4,
SwitchKeymapAction = 5, SwitchLayerAction = 5,
MouseAction = 6, SwitchKeymapAction = 6,
PlayMacroAction = 7 MouseAction = 7,
PlayMacroAction = 8
} }
let KeyActionType = { let KeyActionType = {
NoneAction : 'none', NoneAction : 'none',
KeystrokeAction : 'keystroke', KeystrokeAction : 'keystroke',
KeystrokeModifiersAction : 'keystrokeModifiers',
KeystrokeWithModifiersAction : 'keystrokeWithModifiers', KeystrokeWithModifiersAction : 'keystrokeWithModifiers',
DualRoleKeystrokeAction : 'dualRoleKeystroke', DualRoleKeystrokeAction : 'dualRoleKeystroke',
SwitchLayerAction : 'switchLayer', SwitchLayerAction : 'switchLayer',

View File

@@ -6,6 +6,8 @@ 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: case KeyActionType.KeystrokeWithModifiersAction:
return new KeystrokeWithModifiersAction().fromJsObject(jsObject); return new KeystrokeWithModifiersAction().fromJsObject(jsObject);
case KeyActionType.DualRoleKeystrokeAction: case KeyActionType.DualRoleKeystrokeAction:
@@ -27,11 +29,18 @@ class KeyActions extends ClassArray<KeyAction> {
let keyActionFirstByte = buffer.readUInt8(); let keyActionFirstByte = buffer.readUInt8();
buffer.backtrack(); buffer.backtrack();
if (buffer.enableDump) {
process.stdout.write(']\n');
buffer.enableDump = false;
}
switch (keyActionFirstByte) { switch (keyActionFirstByte) {
case KeyActionId.NoneAction: case KeyActionId.NoneAction:
return new NoneAction().fromBinary(buffer); return new NoneAction().fromBinary(buffer);
case KeyActionId.KeystrokeAction: case KeyActionId.KeystrokeAction:
return new KeystrokeAction().fromBinary(buffer); return new KeystrokeAction().fromBinary(buffer);
case KeyActionId.KeystrokeModifiersAction:
return new KeystrokeModifiersAction().fromBinary(buffer);
case KeyActionId.KeystrokeWithModifiersAction: case KeyActionId.KeystrokeWithModifiersAction:
return new KeystrokeWithModifiersAction().fromBinary(buffer); return new KeystrokeWithModifiersAction().fromBinary(buffer);
case KeyActionId.DualRoleKeystrokeAction: case KeyActionId.DualRoleKeystrokeAction:

View File

@@ -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 `<KeystrokeModifiersAction modifierMask="${this.modifierMask}">`;
}
}

View File

@@ -1,7 +1,5 @@
class KeystrokeWithModifiersAction extends KeyAction { class KeystrokeWithModifiersAction extends KeyAction {
static keyActionTypeString = 'keystrokeWithModifiers';
modifierMask: number; modifierMask: number;
private _scancode: number; private _scancode: number;
@@ -19,7 +17,7 @@ class KeystrokeWithModifiersAction extends KeyAction {
_fromJsObject(jsObject: any): KeystrokeWithModifiersAction { _fromJsObject(jsObject: any): KeystrokeWithModifiersAction {
this.assertKeyActionType( this.assertKeyActionType(
jsObject, KeystrokeWithModifiersAction.keyActionTypeString, 'KeystrokeWithModifiersAction'); jsObject, KeyActionType.KeystrokeWithModifiersAction, 'KeystrokeWithModifiersAction');
this.scancode = jsObject.scancode; this.scancode = jsObject.scancode;
this.modifierMask = jsObject.modifierMask; this.modifierMask = jsObject.modifierMask;
return this; return this;
@@ -34,7 +32,7 @@ class KeystrokeWithModifiersAction extends KeyAction {
_toJsObject(): any { _toJsObject(): any {
return { return {
keyActionType: KeystrokeWithModifiersAction.keyActionTypeString, keyActionType: KeyActionType.KeystrokeWithModifiersAction,
scancode: this.scancode, scancode: this.scancode,
modifierMask: this.modifierMask modifierMask: this.modifierMask
}; };

View File

@@ -2,6 +2,7 @@
/// <reference path="KeyActions.ts" /> /// <reference path="KeyActions.ts" />
/// <reference path="KeystrokeAction.ts" /> /// <reference path="KeystrokeAction.ts" />
/// <reference path="KeystrokeWithModifiersAction.ts" /> /// <reference path="KeystrokeWithModifiersAction.ts" />
/// <reference path="KeystrokeModifiersAction.ts" />
/// <reference path="DualRoleKeystrokeAction.ts" /> /// <reference path="DualRoleKeystrokeAction.ts" />
/// <reference path="MouseAction.ts" /> /// <reference path="MouseAction.ts" />
/// <reference path="PlayMacroAction.ts" /> /// <reference path="PlayMacroAction.ts" />

View File

@@ -34,6 +34,10 @@
"keyActionType": "keystroke", "keyActionType": "keystroke",
"scancode": 110 "scancode": 110
}, },
{
"keyActionType": "keystrokeModifiers",
"modifierMask":33
},
{ {
"keyActionType": "keystrokeWithModifiers", "keyActionType": "keystrokeWithModifiers",
"scancode": 120, "scancode": 120,