Add MouseAction.

This commit is contained in:
László Monda
2016-03-29 13:05:48 +02:00
parent 03dbf3a142
commit 00827b1b94
6 changed files with 85 additions and 48 deletions

View File

@@ -2,9 +2,11 @@ class KeyAction {
static fromJsObject(jsObject: any): KeyAction {
switch (jsObject.keyActionType) {
case KeystrokeAction.actionTypeString:
case KeystrokeAction.keyActionTypeString:
return new KeystrokeAction().fromJsObject(jsObject);
case KeyActionNone.actionTypeString:
case MouseAction.keyActionTypeString:
return new MouseAction().fromJsObject(jsObject);
case KeyActionNone.keyActionTypeString:
return new KeyActionNone().fromJsObject(jsObject);
default:
throw 'Invalid KeyAction.keyActionType: "${jsObject.actionType}"';
@@ -17,7 +19,9 @@ class KeyAction {
if (KeystrokeAction.isScancodeValid(keyActionFirstByte)) {
return new KeystrokeAction().fromBinary(buffer);
} else if (keyActionFirstByte === KeyActionNone.keyActionNoneId) {
} else if (keyActionFirstByte === MouseAction.keyActionId) {
return new MouseAction().fromBinary(buffer);
} else if (keyActionFirstByte === KeyActionNone.keyActionId) {
return new KeyActionNone().fromBinary(buffer);
} else {
throw 'Invalid KeyAction first byte "${keyActionFirstByte}"';

View File

@@ -1,11 +1,11 @@
class KeyActionNone extends KeyAction implements Serializable<KeyActionNone> {
static actionTypeString = 'none';
static keyActionNoneId = 0;
static keyActionTypeString = 'none';
static keyActionId = 0;
static keyActionNoneParam = 0;
fromJsObject(jsObject: any): KeyActionNone {
if (jsObject.keyActionType !== KeyActionNone.actionTypeString) {
if (jsObject.keyActionType !== KeyActionNone.keyActionTypeString) {
throw 'Invalid KeyActionNone.keyActionType: "${jsObject.keyActionType}"';
}
return this;
@@ -13,7 +13,7 @@ class KeyActionNone extends KeyAction implements Serializable<KeyActionNone> {
fromBinary(buffer: UhkBuffer): KeyActionNone {
let keyActionId = buffer.readUInt8();
if (keyActionId !== KeyActionNone.keyActionNoneId) {
if (keyActionId !== KeyActionNone.keyActionId) {
throw 'Invalid KeyActionNone.id: ${keyActionId}';
}
@@ -27,12 +27,12 @@ class KeyActionNone extends KeyAction implements Serializable<KeyActionNone> {
toJsObject(): any {
return {
keyActionType: KeyActionNone.actionTypeString
keyActionType: KeyActionNone.keyActionTypeString
};
}
toBinary(buffer: UhkBuffer) {
buffer.writeUInt8(KeyActionNone.keyActionNoneId);
buffer.writeUInt8(KeyActionNone.keyActionId);
buffer.writeUInt8(KeyActionNone.keyActionNoneParam);
}
}

View File

@@ -1,13 +1,13 @@
class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction> {
static actionTypeString = 'keystroke';
static keyActionTypeString = 'keystroke';
static firstValidScancode = 1;
static lastValidScancode = 231;
_scancode: number;
modifierMask: number;
get scancode() {
get scancode(): number {
return this._scancode;
}
@@ -37,7 +37,7 @@ class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction>
toJsObject(): any {
return {
keyActionType: KeystrokeAction.actionTypeString,
keyActionType: KeystrokeAction.keyActionTypeString,
scancode: this.scancode,
modifierMask: this.modifierMask
};

View File

@@ -0,0 +1,68 @@
enum MouseActionParam {
leftClick,
middleClick,
rightClick,
moveUp,
moveDown,
moveLeft,
moveRight,
scrollUp,
scrollDown,
scrollLeft,
scrollRight,
accelerate,
decelerate
}
class MouseAction extends KeyAction implements Serializable<MouseAction> {
static keyActionTypeString = 'mouse';
static keyActionId = 244;
_mouseAction: MouseActionParam;
get mouseAction(): number {
return this._mouseAction;
}
set mouseAction(mouseAction) {
if (!MouseAction.isMouseActionValid(mouseAction)) {
throw 'Invalid MouseAction.mouseAction: ${mouseAction}';
}
this._mouseAction = mouseAction;
}
static isMouseActionValid(keyActionParam): boolean {
return MouseActionParam[keyActionParam] !== undefined;
}
fromJsObject(jsObject: any): MouseAction {
this.mouseAction = jsObject.mouseAction;
return this;
}
fromBinary(buffer: UhkBuffer): MouseAction {
let keyActionId = buffer.readUInt8();
if (keyActionId !== MouseAction.keyActionId) {
throw 'Invalid MouseAction.id: ${keyActionId}';
}
let keyActionParam = buffer.readUInt8();
if (!MouseAction.isMouseActionValid(keyActionParam)) {
throw 'Invalid MouseAction.param: ${keyActionParam}';
}
return this;
}
toJsObject(): any {
return {
keyActionType: MouseAction.keyActionTypeString,
mouseAction: MouseActionParam[this.mouseAction]
};
}
toBinary(buffer: UhkBuffer) {
buffer.writeUInt8(MouseAction.keyActionId);
buffer.writeUInt8(this.mouseAction);
}
}

View File

@@ -1,3 +1,4 @@
/// <reference path="KeyAction.ts" />
/// <reference path="KeystrokeAction.ts" />
/// <reference path="MouseAction.ts" />
/// <reference path="KeyActionNone.ts" />

View File

@@ -22,7 +22,6 @@ 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_MOUSE = 244;
let KEY_ACTION_ID_PLAY_MACRO = 245;
let KEY_ACTION_ID_SWITCH_KEYMAP = 246;
let KEY_ACTION_ID_NONE = 255;
@@ -34,19 +33,6 @@ let SWITCH_LAYER_TOGGLE = 0x80;
let NONE_ACTION_PADDING = 0;
let MOUSE_ACTION_ID_LEFT_CLICK = 0;
let MOUSE_ACTION_ID_MIDDLE_CLICK = 1;
let MOUSE_ACTION_ID_RIGHT_CLICK = 2;
let MOUSE_ACTION_ID_MOVE_UP = 3;
let MOUSE_ACTION_ID_MOVE_DOWN = 4;
let MOUSE_ACTION_ID_MOVE_LEFT = 5;
let MOUSE_ACTION_ID_MOVE_RIGHT = 6;
let MOUSE_ACTION_ID_SCROLL_UP = 7;
let MOUSE_ACTION_ID_SCROLL_DOWN = 8;
let MOUSE_ACTION_ID_SCROLL_LEFT = 9;
let MOUSE_ACTION_ID_SCROLL_RIGHT = 10;
let MOUSE_ACTION_ID_ACCELERATE = 11;
let MOUSE_ACTION_ID_DECELERATE = 12;
function serializeKeyActions(keyActionsParam) {
keyActionsParam.forEach(function(keyAction) {
@@ -60,9 +46,6 @@ function serializeKeyAction(keyAction) {
case 'dualRoleKeystroke':
serializeDualRoleKeyAction(keyAction);
break;
case 'mouse':
serializeMouseAction(keyAction);
break;
case 'playMacro':
serializeMacroAction(keyAction);
break;
@@ -94,25 +77,6 @@ function serializeDualRoleKeyAction(dualRoleKeyAction) {
writer.writeUInt8(dualRoleKeyAction.scancode);
}
function serializeMouseAction(mouseAction) {
writer.writeUInt8(KEY_ACTION_ID_MOUSE);
writer.writeUInt8({
leftClick : MOUSE_ACTION_ID_LEFT_CLICK,
middleClick: MOUSE_ACTION_ID_MIDDLE_CLICK,
rightClick : MOUSE_ACTION_ID_RIGHT_CLICK,
moveUp : MOUSE_ACTION_ID_MOVE_UP,
moveDown : MOUSE_ACTION_ID_MOVE_DOWN,
moveLeft : MOUSE_ACTION_ID_MOVE_LEFT,
moveRight : MOUSE_ACTION_ID_MOVE_RIGHT,
scrollUp : MOUSE_ACTION_ID_SCROLL_UP,
scrollDown : MOUSE_ACTION_ID_SCROLL_DOWN,
scrollLeft : MOUSE_ACTION_ID_SCROLL_LEFT,
scrollRight: MOUSE_ACTION_ID_SCROLL_RIGHT,
accelerate : MOUSE_ACTION_ID_ACCELERATE,
decelerate : MOUSE_ACTION_ID_DECELERATE
}[mouseAction.mouseAction]);
}
function serializeMacroAction(macroAction) {
writer.writeUInt8(KEY_ACTION_ID_PLAY_MACRO);
writer.writeUInt8(macroAction.macroId);