Add UhkBuffer.backtrack() and implement the KeyAction class.

This commit is contained in:
László Monda
2016-03-26 02:52:50 +01:00
parent 32646f3616
commit 9d77d7212b
4 changed files with 55 additions and 10 deletions

30
model/KeyAction.ts Normal file
View 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}"';
}
}
}