Add UhkBuffer.backtrack() and implement the KeyAction class.
This commit is contained in:
30
model/KeyAction.ts
Normal file
30
model/KeyAction.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/// <reference path="KeystrokeAction.ts" />
|
||||
|
||||
class KeyAction {
|
||||
|
||||
static fromJsObject(jsObject: any): KeyAction {
|
||||
switch (jsObject.actionType) {
|
||||
case 'keyStroke':
|
||||
let keystrokeAction = new KeystrokeAction();
|
||||
keystrokeAction.fromJsObject(jsObject);
|
||||
return keystrokeAction;
|
||||
default:
|
||||
throw 'Unknown KeyAction actionType "${jsObject.actionType}"';
|
||||
}
|
||||
}
|
||||
|
||||
static fromBinary(buffer: UhkBuffer) {
|
||||
let keyActionFirstByte = buffer.readUInt8();
|
||||
buffer.backtrack();
|
||||
|
||||
if (KeystrokeAction.firstValidScancode <= keyActionFirstByte &&
|
||||
keyActionFirstByte <= KeystrokeAction.lastValidScancode)
|
||||
{
|
||||
let keystrokeAction = new KeystrokeAction();
|
||||
keystrokeAction.fromBinary(buffer);
|
||||
return keystrokeAction;
|
||||
} else {
|
||||
throw 'Unknown KeyAction first byte "${keyActionFirstByte}"';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user