committed by
László Monda
parent
22a59160fb
commit
6c271c219a
@@ -140,7 +140,7 @@ export class MacroItemComponent implements OnInit, OnChanges {
|
||||
}
|
||||
|
||||
if (action.hasScancode()) {
|
||||
const scancode: string = (this.mapper.scanCodeToText(action.scancode) || ['Unknown']).join(' ');
|
||||
const scancode: string = (this.mapper.scanCodeToText(action.scancode, action.type) || ['Unknown']).join(' ');
|
||||
if (scancode) {
|
||||
this.title += scancode;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { KeyAction, KeystrokeAction, keyActionType } from '../key-action';
|
||||
import { KeystrokeType } from '../key-action/keystroke-type';
|
||||
import { DelayMacroAction } from './delay-macro-action';
|
||||
import { KeyMacroAction } from './key-macro-action';
|
||||
import { MacroAction, MacroSubAction, macroActionType } from './macro-action';
|
||||
@@ -11,6 +12,7 @@ interface JsObjectEditableMacroAction {
|
||||
macroActionType: string;
|
||||
action?: string;
|
||||
scancode?: number;
|
||||
type?: string;
|
||||
modifierMask?: number;
|
||||
mouseButtonsMask?: number;
|
||||
x?: number;
|
||||
@@ -23,6 +25,7 @@ export class EditableMacroAction {
|
||||
macroActionType: string;
|
||||
action: MacroSubAction;
|
||||
// Key macro action properties
|
||||
type: number;
|
||||
scancode: number;
|
||||
modifierMask: number;
|
||||
// Mouse macro action properties
|
||||
@@ -46,6 +49,7 @@ export class EditableMacroAction {
|
||||
switch (this.macroActionType) {
|
||||
case macroActionType.KeyMacroAction:
|
||||
this.action = MacroSubAction[jsObject.action];
|
||||
this.type = KeystrokeType[jsObject.type];
|
||||
this.scancode = jsObject.scancode;
|
||||
this.modifierMask = jsObject.modifierMask;
|
||||
break;
|
||||
@@ -78,6 +82,7 @@ export class EditableMacroAction {
|
||||
action: this.action,
|
||||
delay: this.delay,
|
||||
text: this.text,
|
||||
type: KeystrokeType[this.type],
|
||||
scancode: this.scancode,
|
||||
modifierMask: this.modifierMask,
|
||||
mouseButtonsMask: this.mouseButtonsMask,
|
||||
@@ -95,6 +100,7 @@ export class EditableMacroAction {
|
||||
fromKeyAction(keyAction: KeyAction): void {
|
||||
const data = keyAction.toJsonObject();
|
||||
this.scancode = data.scancode;
|
||||
this.type = KeystrokeType[data.type as string];
|
||||
this.modifierMask = data.modifierMask;
|
||||
}
|
||||
|
||||
@@ -139,6 +145,7 @@ export class EditableMacroAction {
|
||||
return new KeyMacroAction().fromJsonObject({
|
||||
macroActionType: this.macroActionType,
|
||||
action: MacroSubAction[this.action],
|
||||
type: KeystrokeType[this.type],
|
||||
scancode: this.scancode,
|
||||
modifierMask: this.modifierMask
|
||||
});
|
||||
|
||||
@@ -2,12 +2,12 @@ import { assertEnum, assertUInt8 } from '../../assert';
|
||||
import { UhkBuffer } from '../../uhk-buffer';
|
||||
import { KeyModifiers } from '../key-modifiers';
|
||||
import { MacroAction, MacroActionId, MacroSubAction, macroActionType } from './macro-action';
|
||||
|
||||
const NUM_OF_COMBINATIONS = 3; // Cases: scancode, modifer, both
|
||||
import { KeystrokeType } from '../key-action/keystroke-type';
|
||||
|
||||
interface JsObjectKeyMacroAction {
|
||||
macroActionType: string;
|
||||
action: string;
|
||||
type?: string;
|
||||
scancode?: number;
|
||||
modifierMask?: number;
|
||||
}
|
||||
@@ -17,6 +17,9 @@ export class KeyMacroAction extends MacroAction {
|
||||
@assertEnum(MacroSubAction)
|
||||
action: MacroSubAction;
|
||||
|
||||
@assertEnum(KeystrokeType)
|
||||
type: KeystrokeType;
|
||||
|
||||
@assertUInt8
|
||||
scancode: number;
|
||||
|
||||
@@ -29,6 +32,7 @@ export class KeyMacroAction extends MacroAction {
|
||||
return;
|
||||
}
|
||||
this.action = other.action;
|
||||
this.type = other.type;
|
||||
this.scancode = other.scancode;
|
||||
this.modifierMask = other.modifierMask;
|
||||
}
|
||||
@@ -36,6 +40,11 @@ export class KeyMacroAction extends MacroAction {
|
||||
fromJsonObject(jsObject: JsObjectKeyMacroAction): KeyMacroAction {
|
||||
this.assertMacroActionType(jsObject);
|
||||
this.action = MacroSubAction[jsObject.action];
|
||||
if (jsObject.type === 'media') {
|
||||
this.type = jsObject.scancode < 256 ? KeystrokeType.shortMedia : KeystrokeType.longMedia;
|
||||
} else {
|
||||
this.type = KeystrokeType[jsObject.type];
|
||||
}
|
||||
this.scancode = jsObject.scancode;
|
||||
this.modifierMask = jsObject.modifierMask;
|
||||
return this;
|
||||
@@ -44,12 +53,14 @@ export class KeyMacroAction extends MacroAction {
|
||||
fromBinary(buffer: UhkBuffer): KeyMacroAction {
|
||||
const macroActionId: MacroActionId = this.readAndAssertMacroActionId(buffer);
|
||||
let keyMacroType: number = macroActionId - MacroActionId.KeyMacroAction;
|
||||
this.action = Math.floor(keyMacroType / NUM_OF_COMBINATIONS);
|
||||
keyMacroType %= NUM_OF_COMBINATIONS;
|
||||
if (keyMacroType % 2 === 0) {
|
||||
this.action = keyMacroType & 0b11;
|
||||
keyMacroType >>= 2;
|
||||
this.type = keyMacroType & 0b11;
|
||||
keyMacroType >>= 2;
|
||||
if (keyMacroType & 0b10) {
|
||||
this.scancode = buffer.readUInt8();
|
||||
}
|
||||
if (keyMacroType !== 0) {
|
||||
if (keyMacroType & 0b01) {
|
||||
this.modifierMask = buffer.readUInt8();
|
||||
}
|
||||
return this;
|
||||
@@ -62,6 +73,11 @@ export class KeyMacroAction extends MacroAction {
|
||||
};
|
||||
|
||||
if (this.hasScancode()) {
|
||||
if (this.type === KeystrokeType.shortMedia || this.type === KeystrokeType.longMedia) {
|
||||
jsObject.type = 'media';
|
||||
} else {
|
||||
jsObject.type = KeystrokeType[this.type];
|
||||
}
|
||||
jsObject.scancode = this.scancode;
|
||||
}
|
||||
|
||||
@@ -73,15 +89,13 @@ export class KeyMacroAction extends MacroAction {
|
||||
}
|
||||
|
||||
toBinary(buffer: UhkBuffer) {
|
||||
let keyMacroType: number = MacroActionId.KeyMacroAction;
|
||||
keyMacroType += NUM_OF_COMBINATIONS * this.action;
|
||||
let TYPE_OFFSET = 0;
|
||||
TYPE_OFFSET |= this.action;
|
||||
TYPE_OFFSET |= this.type << 2;
|
||||
TYPE_OFFSET |= ((this.hasScancode() ? 2 : 0) + (this.hasModifiers() ? 1 : 0)) << 4;
|
||||
|
||||
const keyMacroType: number = MacroActionId.KeyMacroAction + TYPE_OFFSET;
|
||||
|
||||
if (this.hasModifiers()) {
|
||||
++keyMacroType;
|
||||
if (this.hasScancode()) {
|
||||
++keyMacroType;
|
||||
}
|
||||
}
|
||||
buffer.writeUInt8(keyMacroType);
|
||||
if (this.hasScancode()) {
|
||||
buffer.writeUInt8(this.scancode);
|
||||
|
||||
@@ -3,30 +3,24 @@ import { UhkBuffer } from '../../uhk-buffer';
|
||||
export enum MacroActionId {
|
||||
KeyMacroAction = 0,
|
||||
/*
|
||||
0 - 8 are reserved for KeyMacroAction
|
||||
PressKeyMacroAction with scancode: 0
|
||||
PressKeyMacroAction with modifiers: 1
|
||||
PressKeyMacroAction with scancode and modifiers 2
|
||||
HoldKeyMacroAction with scancode: 3
|
||||
HoldKeyMacroAction with modifiers: 4
|
||||
HoldKeyMacroAction with scancode and modifiers 5
|
||||
ReleaseKeyMacroAction with scancode: 6
|
||||
ReleaseKeyMacroAction with modifiers: 7
|
||||
ReleaseKeyMacroAction with scancode and modifiers 8
|
||||
0 - 63 are reserved for KeyMacroAction
|
||||
2 bits for: PressKeyMacroAction / HoldKeyMacroAction / ReleaseKeyMacroAction / undefined
|
||||
2 bits for: with only scancode / only modifiers / both scancode and modifiers / undefined
|
||||
2 bits for: scancode type basic, short media, long media, system. It should be only used if scancode does exist.
|
||||
*/
|
||||
LastKeyMacroAction = 8,
|
||||
MouseButtonMacroAction = 9,
|
||||
LastKeyMacroAction = 63,
|
||||
MouseButtonMacroAction = 64,
|
||||
/*
|
||||
9 - 11 are reserved for MouseButtonMacroAction
|
||||
PressMouseButtonsMacroAction = 9,
|
||||
HoldMouseButtonsMacroAction = 10,
|
||||
ReleaseMouseButtonsMacroAction = 11,
|
||||
64 - 66 are reserved for MouseButtonMacroAction
|
||||
PressMouseButtonsMacroAction = 64,
|
||||
HoldMouseButtonsMacroAction = 65,
|
||||
ReleaseMouseButtonsMacroAction = 66,
|
||||
*/
|
||||
LastMouseButtonMacroAction = 11,
|
||||
MoveMouseMacroAction = 12,
|
||||
ScrollMouseMacroAction = 13,
|
||||
DelayMacroAction = 14,
|
||||
TextMacroAction = 15
|
||||
LastMouseButtonMacroAction = 66,
|
||||
MoveMouseMacroAction = 67,
|
||||
ScrollMouseMacroAction = 68,
|
||||
DelayMacroAction = 69,
|
||||
TextMacroAction = 70
|
||||
}
|
||||
|
||||
export enum MacroSubAction {
|
||||
|
||||
@@ -1617,16 +1617,19 @@
|
||||
{
|
||||
"macroActionType": "key",
|
||||
"action": "press",
|
||||
"type": "basic",
|
||||
"scancode": 111
|
||||
},
|
||||
{
|
||||
"macroActionType": "key",
|
||||
"action": "hold",
|
||||
"type": "basic",
|
||||
"scancode": 83
|
||||
},
|
||||
{
|
||||
"macroActionType": "key",
|
||||
"action": "release",
|
||||
"type": "basic",
|
||||
"scancode": 112
|
||||
},
|
||||
{
|
||||
@@ -1687,6 +1690,7 @@
|
||||
{
|
||||
"macroActionType": "key",
|
||||
"action": "press",
|
||||
"type": "basic",
|
||||
"scancode": 111
|
||||
},
|
||||
{
|
||||
@@ -1710,4 +1714,4 @@
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user