Make long media key macro actions work. (#621)
* Make long media key macro actions work. * fix: macro key action mapping
This commit is contained in:
+27
-11
@@ -1,4 +1,4 @@
|
|||||||
import { assertEnum, assertUInt8 } from '../../assert';
|
import { assertEnum, assertUInt8, assertUInt16 } from '../../assert';
|
||||||
import { UhkBuffer } from '../../uhk-buffer';
|
import { UhkBuffer } from '../../uhk-buffer';
|
||||||
import { KeyModifiers } from '../key-modifiers';
|
import { KeyModifiers } from '../key-modifiers';
|
||||||
import { MacroAction, MacroActionId, MacroKeySubAction, macroActionType } from './macro-action';
|
import { MacroAction, MacroActionId, MacroKeySubAction, macroActionType } from './macro-action';
|
||||||
@@ -20,12 +20,24 @@ export class KeyMacroAction extends MacroAction {
|
|||||||
@assertEnum(KeystrokeType)
|
@assertEnum(KeystrokeType)
|
||||||
type: KeystrokeType;
|
type: KeystrokeType;
|
||||||
|
|
||||||
@assertUInt8
|
|
||||||
scancode: number;
|
|
||||||
|
|
||||||
@assertUInt8
|
@assertUInt8
|
||||||
modifierMask: number;
|
modifierMask: number;
|
||||||
|
|
||||||
|
@assertUInt16
|
||||||
|
private _scancode: number;
|
||||||
|
|
||||||
|
set scancode(scancode: number) {
|
||||||
|
this._scancode = scancode;
|
||||||
|
if (this.type !== KeystrokeType.shortMedia && this.type !== KeystrokeType.longMedia) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.type = scancode < 256 ? KeystrokeType.shortMedia : KeystrokeType.longMedia;
|
||||||
|
}
|
||||||
|
|
||||||
|
get scancode() {
|
||||||
|
return this._scancode;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(other?: KeyMacroAction) {
|
constructor(other?: KeyMacroAction) {
|
||||||
super();
|
super();
|
||||||
if (!other) {
|
if (!other) {
|
||||||
@@ -33,7 +45,7 @@ export class KeyMacroAction extends MacroAction {
|
|||||||
}
|
}
|
||||||
this.action = other.action;
|
this.action = other.action;
|
||||||
this.type = other.type;
|
this.type = other.type;
|
||||||
this.scancode = other.scancode;
|
this._scancode = other._scancode;
|
||||||
this.modifierMask = other.modifierMask;
|
this.modifierMask = other.modifierMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +57,7 @@ export class KeyMacroAction extends MacroAction {
|
|||||||
} else {
|
} else {
|
||||||
this.type = KeystrokeType[jsObject.type];
|
this.type = KeystrokeType[jsObject.type];
|
||||||
}
|
}
|
||||||
this.scancode = jsObject.scancode;
|
this._scancode = jsObject.scancode;
|
||||||
this.modifierMask = jsObject.modifierMask;
|
this.modifierMask = jsObject.modifierMask;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -58,7 +70,7 @@ export class KeyMacroAction extends MacroAction {
|
|||||||
this.type = keyMacroType & 0b11;
|
this.type = keyMacroType & 0b11;
|
||||||
keyMacroType >>= 2;
|
keyMacroType >>= 2;
|
||||||
if (keyMacroType & 0b10) {
|
if (keyMacroType & 0b10) {
|
||||||
this.scancode = buffer.readUInt8();
|
this._scancode = this.type === KeystrokeType.longMedia ? buffer.readUInt16() : buffer.readUInt8();
|
||||||
}
|
}
|
||||||
if (keyMacroType & 0b01) {
|
if (keyMacroType & 0b01) {
|
||||||
this.modifierMask = buffer.readUInt8();
|
this.modifierMask = buffer.readUInt8();
|
||||||
@@ -78,7 +90,7 @@ export class KeyMacroAction extends MacroAction {
|
|||||||
} else {
|
} else {
|
||||||
jsObject.type = KeystrokeType[this.type];
|
jsObject.type = KeystrokeType[this.type];
|
||||||
}
|
}
|
||||||
jsObject.scancode = this.scancode;
|
jsObject.scancode = this._scancode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.hasModifiers()) {
|
if (this.hasModifiers()) {
|
||||||
@@ -98,7 +110,11 @@ export class KeyMacroAction extends MacroAction {
|
|||||||
|
|
||||||
buffer.writeUInt8(keyMacroType);
|
buffer.writeUInt8(keyMacroType);
|
||||||
if (this.hasScancode()) {
|
if (this.hasScancode()) {
|
||||||
buffer.writeUInt8(this.scancode);
|
if (this.type === KeystrokeType.longMedia) {
|
||||||
|
buffer.writeUInt16(this.scancode);
|
||||||
|
} else {
|
||||||
|
buffer.writeUInt8(this.scancode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (this.hasModifiers()) {
|
if (this.hasModifiers()) {
|
||||||
buffer.writeUInt8(this.modifierMask);
|
buffer.writeUInt8(this.modifierMask);
|
||||||
@@ -106,7 +122,7 @@ export class KeyMacroAction extends MacroAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string {
|
||||||
return `<KeyMacroAction action="${this.action}" scancode="${this.scancode}" modifierMask="${this.modifierMask}">`;
|
return `<KeyMacroAction action="${this.action}" scancode="${this._scancode}" modifierMask="${this.modifierMask}">`;
|
||||||
}
|
}
|
||||||
|
|
||||||
isModifierActive(modifier: KeyModifiers): boolean {
|
isModifierActive(modifier: KeyModifiers): boolean {
|
||||||
@@ -114,7 +130,7 @@ export class KeyMacroAction extends MacroAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hasScancode(): boolean {
|
hasScancode(): boolean {
|
||||||
return !!this.scancode;
|
return !!this._scancode;
|
||||||
}
|
}
|
||||||
|
|
||||||
hasModifiers(): boolean {
|
hasModifiers(): boolean {
|
||||||
|
|||||||
+1
-1
@@ -67,7 +67,7 @@ export class MacroKeyTabComponent extends MacroBaseComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getKeyMacroAction(): KeyMacroAction {
|
getKeyMacroAction(): KeyMacroAction {
|
||||||
const keyMacroAction = Object.assign(new KeyMacroAction(), this.keypressTab.toKeyAction());
|
const keyMacroAction = new KeyMacroAction(this.keypressTab.toKeyAction() as any);
|
||||||
keyMacroAction.action = this.getActionType(this.activeTab);
|
keyMacroAction.action = this.getActionType(this.activeTab);
|
||||||
return keyMacroAction;
|
return keyMacroAction;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ export class KeypressTabComponent extends Tab implements OnChanges {
|
|||||||
const scTypePair = this.toScancodeTypePair(this.selectedScancodeOption);
|
const scTypePair = this.toScancodeTypePair(this.selectedScancodeOption);
|
||||||
keystrokeAction.scancode = scTypePair[0];
|
keystrokeAction.scancode = scTypePair[0];
|
||||||
if (scTypePair[1] === 'media') {
|
if (scTypePair[1] === 'media') {
|
||||||
keystrokeAction.type = KeystrokeType.shortMedia;
|
keystrokeAction.type = keystrokeAction.scancode > 255 ? KeystrokeType.longMedia : KeystrokeType.shortMedia;
|
||||||
} else {
|
} else {
|
||||||
keystrokeAction.type = KeystrokeType[scTypePair[1]];
|
keystrokeAction.type = KeystrokeType[scTypePair[1]];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user