Move the classes of the config items into the newly created config-items directory.
This commit is contained in:
50
config-serializer/config-items/KeystrokeAction.ts
Normal file
50
config-serializer/config-items/KeystrokeAction.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction> {
|
||||
|
||||
static actionTypeString = 'keystroke';
|
||||
static firstValidScancode = 1;
|
||||
static lastValidScancode = 231;
|
||||
|
||||
_scancode: number;
|
||||
modifierMask: number;
|
||||
|
||||
get scancode() {
|
||||
return this._scancode;
|
||||
}
|
||||
|
||||
set scancode(value) {
|
||||
if (!KeystrokeAction.isScancodeValid(value)) {
|
||||
throw 'Invalid KeystrokeAction.scancode: ${scancode}';
|
||||
}
|
||||
this._scancode = value;
|
||||
}
|
||||
|
||||
static isScancodeValid(scancode) {
|
||||
return KeystrokeAction.firstValidScancode <= scancode &&
|
||||
scancode <= KeystrokeAction.lastValidScancode;
|
||||
}
|
||||
|
||||
fromJsObject(jsObject: any): KeystrokeAction {
|
||||
this.scancode = jsObject.scancode;
|
||||
this.modifierMask = jsObject.modifierMask;
|
||||
return this;
|
||||
}
|
||||
|
||||
fromBinary(buffer: UhkBuffer): KeystrokeAction {
|
||||
this.scancode = buffer.readUInt8();
|
||||
this.modifierMask = buffer.readUInt8();
|
||||
return this;
|
||||
}
|
||||
|
||||
toJsObject(): any {
|
||||
return {
|
||||
keyActionType: KeystrokeAction.actionTypeString,
|
||||
scancode: this.scancode,
|
||||
modifierMask: this.modifierMask
|
||||
};
|
||||
}
|
||||
|
||||
toBinary(buffer: UhkBuffer) {
|
||||
buffer.writeUInt8(this.scancode);
|
||||
buffer.writeUInt8(this.modifierMask);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user