Add DualRoleKeystrokeAction.

This commit is contained in:
László Monda
2016-03-30 01:48:08 +02:00
parent 7660bdb729
commit 94e5d55d8f
4 changed files with 64 additions and 49 deletions

View File

@@ -0,0 +1,61 @@
enum LongPressActionId {
leftCtrl = 233,
leftShift,
leftAlt,
leftSuper,
rightCtrl,
rightShift,
rightAlt,
rightSuper,
mod,
fn,
mouse,
}
class DualRoleKeystrokeAction extends KeyAction implements Serializable<DualRoleKeystrokeAction> {
static keyActionTypeString = 'dualRoleKeystroke';
public scancode;
private _longPressAction: LongPressActionId;
get longPressAction(): number {
return this._longPressAction;
}
set longPressAction(value) {
if (!DualRoleKeystrokeAction.isDualRoleKeystrokeActionValid(value)) {
throw 'Invalid DualRoleKeystrokeAction.longPressAction: ${value}';
}
this._longPressAction = value;
}
static isDualRoleKeystrokeActionValid(keyActionId): boolean {
return LongPressActionId[keyActionId] !== undefined;
}
fromJsObject(jsObject: any): DualRoleKeystrokeAction {
this.longPressAction = jsObject.longPressAction;
this.scancode = jsObject.scancode;
return this;
}
fromBinary(buffer: UhkBuffer): DualRoleKeystrokeAction {
this.longPressAction = buffer.readUInt8();
this.scancode = buffer.readUInt8();
return this;
}
toJsObject(): any {
return {
keyActionType: DualRoleKeystrokeAction.keyActionTypeString,
longPressAction: LongPressActionId[this.longPressAction],
scancode: this.scancode
};
}
toBinary(buffer: UhkBuffer) {
buffer.writeUInt8(this.longPressAction);
buffer.writeUInt8(this.scancode);
}
}

View File

@@ -4,9 +4,10 @@ class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction>
static firstValidScancode = 1;
static lastValidScancode = 231;
private _scancode: number;
modifierMask: number;
private _scancode: number;
get scancode(): number {
return this._scancode;
}

View File

@@ -1,5 +1,6 @@
/// <reference path="KeyAction.ts" />
/// <reference path="KeystrokeAction.ts" />
/// <reference path="DualRoleKeystrokeAction.ts" />
/// <reference path="MouseAction.ts" />
/// <reference path="PlayMacroAction.ts" />
/// <reference path="SwitchKeymapAction.ts" />

View File

@@ -8,42 +8,13 @@ let writer = new UhkBuffer();
let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json'));
let keyActions = uhkConfig.keymaps[0].layers[0].modules[0].keyActions;
let ARRAY_LAST_ELEMENT_ID = 0;
let KEY_ACTION_ID_SWITCH_LAYER = 232;
let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_MOD = 233;
let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_FN = 234;
let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_MOUSE = 235;
let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_CTRL = 236;
let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_SHIFT = 237;
let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_ALT = 238;
let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_SUPER = 239;
let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_CTRL = 240;
let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_SHIFT = 241;
let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_ALT = 242;
let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_SUPER = 243;
let KEY_ACTION_ID_NONE = 255;
let SWITCH_LAYER_MOD = 0;
let SWITCH_LAYER_FN = 1;
let SWITCH_LAYER_MOUSE = 2;
let SWITCH_LAYER_TOGGLE = 0x80;
let NONE_ACTION_PADDING = 0;
function serializeKeyActions(keyActionsParam) {
keyActionsParam.forEach(function(keyAction) {
serializeKeyAction(keyAction);
});
writer.writeUInt8(ARRAY_LAST_ELEMENT_ID);
}
function serializeKeyAction(keyAction) {
switch (keyAction.actionType) {
case 'dualRoleKeystroke':
serializeDualRoleKeyAction(keyAction);
break;
case 'switchLayer':
serializeSwitchLayerAction(keyAction);
break;
@@ -52,25 +23,7 @@ function serializeKeyAction(keyAction) {
}
}
function serializeDualRoleKeyAction(dualRoleKeyAction) {
writer.writeUInt8({
mod : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_MOD,
fn : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_FN,
mouse : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_MOUSE,
leftControl : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_CTRL,
leftShift : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_SHIFT,
leftAlt : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_ALT,
leftSuper : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_SUPER,
rightControl: KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_CTRL,
rightShift : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_SHIFT,
rightAlt : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_ALT,
rightSuper : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_SUPER
}[dualRoleKeyAction.longPressAction]);
writer.writeUInt8(dualRoleKeyAction.scancode);
}
function serializeSwitchLayerAction(switchLayerAction) {
writer.writeUInt8(KEY_ACTION_ID_SWITCH_LAYER);
writer.writeUInt8({
mod : SWITCH_LAYER_MOD,
fn : SWITCH_LAYER_FN,
@@ -78,5 +31,4 @@ function serializeSwitchLayerAction(switchLayerAction) {
}[switchLayerAction] | switchLayerAction.toggle ? SWITCH_LAYER_TOGGLE : 0);
}
//serializeKeyActions(keyActions);
fs.writeFileSync('uhk-config.bin', writer.buffer);