Add KeyActionNone

This commit is contained in:
László Monda
2016-03-26 14:58:57 +01:00
parent 252b0969d6
commit cbf83cf778
3 changed files with 47 additions and 4 deletions

View File

@@ -1,9 +1,14 @@
/// <reference path="KeyActionNone.ts" />
/// <reference path="KeystrokeAction.ts" />
class KeyAction {
static fromJsObject(jsObject: any): KeyAction {
switch (jsObject.actionType) {
case 'none':
let keyActionNone = new KeyActionNone();
keyActionNone.fromJsObject(jsObject);
return keyActionNone;
case 'keyStroke':
let keystrokeAction = new KeystrokeAction();
keystrokeAction.fromJsObject(jsObject);
@@ -17,12 +22,14 @@ class KeyAction {
let keyActionFirstByte = buffer.readUInt8();
buffer.backtrack();
if (KeystrokeAction.firstValidScancode <= keyActionFirstByte &&
keyActionFirstByte <= KeystrokeAction.lastValidScancode)
{
if (KeystrokeAction.isScancodeValid(keyActionFirstByte)) {
let keystrokeAction = new KeystrokeAction();
keystrokeAction.fromBinary(buffer);
return keystrokeAction;
} else if (keyActionFirstByte === KeyActionNone.keyActionNoneId) {
let keyActionNone = new KeyActionNone();
keyActionNone.fromBinary(buffer);
return keyActionNone;
} else {
throw 'Unknown KeyAction first byte "${keyActionFirstByte}"';
}