@difizen/mana-core
Version:
701 lines (697 loc) • 27.7 kB
JavaScript
"use strict";
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.KeyboardLayoutService = void 0;
var _manaCommon = require("@difizen/mana-common");
var _manaSyringe = require("@difizen/mana-syringe");
var _keyboardProtocol = require("./keyboard-protocol");
var _keys = require("./keys");
var _dec, _class;
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable no-param-reassign */
/* eslint-disable no-restricted-syntax */
/* eslint-disable class-methods-use-this */
/* eslint-disable no-plusplus */
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var KeyboardLayoutService = exports.KeyboardLayoutService = (_dec = (0, _manaSyringe.singleton)(), _dec(_class = /*#__PURE__*/function () {
function KeyboardLayoutService(layoutProvider, layoutChangeNotifier, keyValidator) {
_classCallCheck(this, KeyboardLayoutService);
this.keyboardLayoutChanged = new _manaCommon.Emitter();
this.layoutProvider = layoutProvider;
this.layoutChangeNotifier = layoutChangeNotifier;
this.keyValidator = keyValidator;
}
KeyboardLayoutService = (0, _manaSyringe.optional)()(KeyboardLayoutService, undefined, 2) || KeyboardLayoutService;
KeyboardLayoutService = (0, _manaSyringe.inject)(_keyboardProtocol.KeyValidator)(KeyboardLayoutService, undefined, 2) || KeyboardLayoutService;
KeyboardLayoutService = (0, _manaSyringe.inject)(_keyboardProtocol.KeyboardLayoutChangeNotifier)(KeyboardLayoutService, undefined, 1) || KeyboardLayoutService;
KeyboardLayoutService = (0, _manaSyringe.inject)(_keyboardProtocol.KeyboardLayoutProvider)(KeyboardLayoutService, undefined, 0) || KeyboardLayoutService;
_createClass(KeyboardLayoutService, [{
key: "updateLayout",
value: function updateLayout(newLayout) {
var transformed = this.transformNativeLayout(newLayout);
this.currentLayout = transformed;
this.keyboardLayoutChanged.fire(transformed);
return transformed;
}
}, {
key: "onKeyboardLayoutChanged",
get: function get() {
return this.keyboardLayoutChanged.event;
}
}, {
key: "initialize",
value: function () {
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
var _this = this;
var initialLayout;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
this.layoutChangeNotifier.onDidChangeNativeLayout(function (newLayout) {
return _this.updateLayout(newLayout);
});
_context.next = 3;
return this.layoutProvider.getNativeLayout();
case 3:
initialLayout = _context.sent;
this.updateLayout(initialLayout);
case 5:
case "end":
return _context.stop();
}
}, _callee, this);
}));
function initialize() {
return _initialize.apply(this, arguments);
}
return initialize;
}()
/**
* Resolve a KeyCode of a keybinding using the current keyboard layout.
* If no keyboard layout has been detected or the layout does not contain the
* key used in the KeyCode, the KeyCode is returned unchanged.
*/
}, {
key: "resolveKeyCode",
value: function resolveKeyCode(inCode) {
var layout = this.currentLayout;
if (layout && inCode.key) {
for (var shift = 0; shift <= 1; shift++) {
var index = this.getCharacterIndex(inCode.key, !!shift);
var mappedCode = layout.key2KeyCode[index];
if (mappedCode) {
var transformed = this.transformKeyCode(inCode, mappedCode, !!shift);
if (transformed) {
return transformed;
}
}
}
}
return inCode;
}
/**
* Return the character shown on the user's keyboard for the given key.
* Use this to determine UI representations of keybindings.
*/
}, {
key: "getKeyboardCharacter",
value: function getKeyboardCharacter(key) {
var layout = this.currentLayout;
if (layout) {
var value = layout.code2Character[key.code];
if (value && value.replace(/[\n\r\t]/g, '')) {
return value;
}
}
return key.easyString;
}
/**
* Called when a KeyboardEvent is processed by the KeybindingRegistry.
* The KeyValidator may trigger a keyboard layout change.
*/
}, {
key: "validateKeyCode",
value: function validateKeyCode(keyCode) {
if (this.keyValidator && keyCode.key && keyCode.character) {
this.keyValidator.validateKey({
code: keyCode.key.code,
character: keyCode.character,
shiftKey: keyCode.shift,
ctrlKey: keyCode.ctrl,
altKey: keyCode.alt
});
}
}
}, {
key: "transformKeyCode",
value: function transformKeyCode(inCode, mappedCode, keyNeedsShift) {
if (!inCode.shift && keyNeedsShift) {
return undefined;
}
if (mappedCode.alt && (inCode.alt || inCode.ctrl || inCode.shift && !keyNeedsShift)) {
return undefined;
}
return new _keys.KeyCode({
key: mappedCode.key,
meta: inCode.meta,
ctrl: inCode.ctrl || mappedCode.alt,
shift: inCode.shift && !keyNeedsShift || mappedCode.shift,
alt: inCode.alt || mappedCode.alt
});
}
}, {
key: "transformNativeLayout",
value: function transformNativeLayout(nativeLayout) {
var key2KeyCode = new Array(2 * (_keys.Key.MAX_KEY_CODE + 1));
var code2Character = {};
var mapping = nativeLayout.mapping;
for (var code in mapping) {
if (Object.prototype.hasOwnProperty.call(mapping, code)) {
var keyMapping = mapping[code];
var mappedKey = _keys.Key.getKey(code);
if (mappedKey && this.shouldIncludeKey(code)) {
if (_manaCommon.isWindows) {
this.addWindowsKeyMapping(key2KeyCode, mappedKey, keyMapping.vkey, keyMapping.value);
} else {
if (keyMapping.value) {
this.addKeyMapping(key2KeyCode, mappedKey, keyMapping.value, false, false);
}
if (keyMapping.withShift) {
this.addKeyMapping(key2KeyCode, mappedKey, keyMapping.withShift, true, false);
}
if (keyMapping.withAltGr) {
this.addKeyMapping(key2KeyCode, mappedKey, keyMapping.withAltGr, false, true);
}
if (keyMapping.withShiftAltGr) {
this.addKeyMapping(key2KeyCode, mappedKey, keyMapping.withShiftAltGr, true, true);
}
}
}
if (keyMapping.value) {
code2Character[code] = keyMapping.value;
}
}
}
return {
key2KeyCode: key2KeyCode,
code2Character: code2Character
};
}
}, {
key: "shouldIncludeKey",
value: function shouldIncludeKey(code) {
// Exclude all numpad keys because they produce values that are already found elsewhere on the keyboard.
// This can cause problems, e.g. if `Numpad3` maps to `PageDown` then commands bound to `PageDown` would
// be resolved to `Digit3` (`Numpad3` is associated with `Key.DIGIT3`), effectively blocking the user
// from typing `3` in an editor.
return !code.startsWith('Numpad');
}
}, {
key: "addKeyMapping",
value: function addKeyMapping(key2KeyCode, mappedKey, value, shift, alt) {
var key = VALUE_TO_KEY[value];
if (key) {
var index = this.getCharacterIndex(key.key, key.shift);
if (key2KeyCode[index] === undefined) {
key2KeyCode[index] = new _keys.KeyCode({
key: mappedKey,
shift: shift,
alt: alt,
character: value
});
}
}
}
}, {
key: "addWindowsKeyMapping",
value: function addWindowsKeyMapping(key2KeyCode, mappedKey, vkey, value) {
var key = VKEY_TO_KEY[vkey];
if (key) {
var index = this.getCharacterIndex(key);
if (key2KeyCode[index] === undefined) {
key2KeyCode[index] = new _keys.KeyCode({
key: mappedKey,
character: value
});
}
}
}
}, {
key: "getCharacterIndex",
value: function getCharacterIndex(key, shift) {
if (shift) {
return _keys.Key.MAX_KEY_CODE + key.keyCode + 1;
}
return key.keyCode;
}
}]);
return KeyboardLayoutService;
}()) || _class);
/**
* Mapping of character values to the corresponding keys on a standard US keyboard layout.
*/
var VALUE_TO_KEY = {
'`': {
key: _keys.Key.BACKQUOTE
},
'~': {
key: _keys.Key.BACKQUOTE,
shift: true
},
'1': {
key: _keys.Key.DIGIT1
},
'!': {
key: _keys.Key.DIGIT1,
shift: true
},
'2': {
key: _keys.Key.DIGIT2
},
'@': {
key: _keys.Key.DIGIT2,
shift: true
},
'3': {
key: _keys.Key.DIGIT3
},
'#': {
key: _keys.Key.DIGIT3,
shift: true
},
'4': {
key: _keys.Key.DIGIT4
},
$: {
key: _keys.Key.DIGIT4,
shift: true
},
'5': {
key: _keys.Key.DIGIT5
},
'%': {
key: _keys.Key.DIGIT5,
shift: true
},
'6': {
key: _keys.Key.DIGIT6
},
'^': {
key: _keys.Key.DIGIT6,
shift: true
},
'7': {
key: _keys.Key.DIGIT7
},
'&': {
key: _keys.Key.DIGIT7,
shift: true
},
'8': {
key: _keys.Key.DIGIT8
},
'*': {
key: _keys.Key.DIGIT8,
shift: true
},
'9': {
key: _keys.Key.DIGIT9
},
'(': {
key: _keys.Key.DIGIT9,
shift: true
},
'0': {
key: _keys.Key.DIGIT0
},
')': {
key: _keys.Key.DIGIT0,
shift: true
},
'-': {
key: _keys.Key.MINUS
},
_: {
key: _keys.Key.MINUS,
shift: true
},
'=': {
key: _keys.Key.EQUAL
},
'+': {
key: _keys.Key.EQUAL,
shift: true
},
a: {
key: _keys.Key.KEY_A
},
A: {
key: _keys.Key.KEY_A,
shift: true
},
b: {
key: _keys.Key.KEY_B
},
B: {
key: _keys.Key.KEY_B,
shift: true
},
c: {
key: _keys.Key.KEY_C
},
C: {
key: _keys.Key.KEY_C,
shift: true
},
d: {
key: _keys.Key.KEY_D
},
D: {
key: _keys.Key.KEY_D,
shift: true
},
e: {
key: _keys.Key.KEY_E
},
E: {
key: _keys.Key.KEY_E,
shift: true
},
f: {
key: _keys.Key.KEY_F
},
F: {
key: _keys.Key.KEY_F,
shift: true
},
g: {
key: _keys.Key.KEY_G
},
G: {
key: _keys.Key.KEY_G,
shift: true
},
h: {
key: _keys.Key.KEY_H
},
H: {
key: _keys.Key.KEY_H,
shift: true
},
i: {
key: _keys.Key.KEY_I
},
I: {
key: _keys.Key.KEY_I,
shift: true
},
j: {
key: _keys.Key.KEY_J
},
J: {
key: _keys.Key.KEY_J,
shift: true
},
k: {
key: _keys.Key.KEY_K
},
K: {
key: _keys.Key.KEY_K,
shift: true
},
l: {
key: _keys.Key.KEY_L
},
L: {
key: _keys.Key.KEY_L,
shift: true
},
m: {
key: _keys.Key.KEY_M
},
M: {
key: _keys.Key.KEY_M,
shift: true
},
n: {
key: _keys.Key.KEY_N
},
N: {
key: _keys.Key.KEY_N,
shift: true
},
o: {
key: _keys.Key.KEY_O
},
O: {
key: _keys.Key.KEY_O,
shift: true
},
p: {
key: _keys.Key.KEY_P
},
P: {
key: _keys.Key.KEY_P,
shift: true
},
q: {
key: _keys.Key.KEY_Q
},
Q: {
key: _keys.Key.KEY_Q,
shift: true
},
r: {
key: _keys.Key.KEY_R
},
R: {
key: _keys.Key.KEY_R,
shift: true
},
s: {
key: _keys.Key.KEY_S
},
S: {
key: _keys.Key.KEY_S,
shift: true
},
t: {
key: _keys.Key.KEY_T
},
T: {
key: _keys.Key.KEY_T,
shift: true
},
u: {
key: _keys.Key.KEY_U
},
U: {
key: _keys.Key.KEY_U,
shift: true
},
v: {
key: _keys.Key.KEY_V
},
V: {
key: _keys.Key.KEY_V,
shift: true
},
w: {
key: _keys.Key.KEY_W
},
W: {
key: _keys.Key.KEY_W,
shift: true
},
x: {
key: _keys.Key.KEY_X
},
X: {
key: _keys.Key.KEY_X,
shift: true
},
y: {
key: _keys.Key.KEY_Y
},
Y: {
key: _keys.Key.KEY_Y,
shift: true
},
z: {
key: _keys.Key.KEY_Z
},
Z: {
key: _keys.Key.KEY_Z,
shift: true
},
'[': {
key: _keys.Key.BRACKET_LEFT
},
'{': {
key: _keys.Key.BRACKET_LEFT,
shift: true
},
']': {
key: _keys.Key.BRACKET_RIGHT
},
'}': {
key: _keys.Key.BRACKET_RIGHT,
shift: true
},
';': {
key: _keys.Key.SEMICOLON
},
':': {
key: _keys.Key.SEMICOLON,
shift: true
},
"'": {
key: _keys.Key.QUOTE
},
'"': {
key: _keys.Key.QUOTE,
shift: true
},
',': {
key: _keys.Key.COMMA
},
'<': {
key: _keys.Key.COMMA,
shift: true
},
'.': {
key: _keys.Key.PERIOD
},
'>': {
key: _keys.Key.PERIOD,
shift: true
},
'/': {
key: _keys.Key.SLASH
},
'?': {
key: _keys.Key.SLASH,
shift: true
},
'\\': {
key: _keys.Key.BACKSLASH
},
'|': {
key: _keys.Key.BACKSLASH,
shift: true
},
'\t': {
key: _keys.Key.TAB
},
'\r': {
key: _keys.Key.ENTER
},
'\n': {
key: _keys.Key.ENTER
},
' ': {
key: _keys.Key.SPACE
}
};
/**
* Mapping of Windows Virtual Keys to the corresponding keys on a standard US keyboard layout.
*/
var VKEY_TO_KEY = {
VK_SHIFT: _keys.Key.SHIFT_LEFT,
VK_LSHIFT: _keys.Key.SHIFT_LEFT,
VK_RSHIFT: _keys.Key.SHIFT_RIGHT,
VK_CONTROL: _keys.Key.CONTROL_LEFT,
VK_LCONTROL: _keys.Key.CONTROL_LEFT,
VK_RCONTROL: _keys.Key.CONTROL_RIGHT,
VK_MENU: _keys.Key.ALT_LEFT,
VK_COMMAND: _keys.Key.OS_LEFT,
VK_LWIN: _keys.Key.OS_LEFT,
VK_RWIN: _keys.Key.OS_RIGHT,
VK_0: _keys.Key.DIGIT0,
VK_1: _keys.Key.DIGIT1,
VK_2: _keys.Key.DIGIT2,
VK_3: _keys.Key.DIGIT3,
VK_4: _keys.Key.DIGIT4,
VK_5: _keys.Key.DIGIT5,
VK_6: _keys.Key.DIGIT6,
VK_7: _keys.Key.DIGIT7,
VK_8: _keys.Key.DIGIT8,
VK_9: _keys.Key.DIGIT9,
VK_A: _keys.Key.KEY_A,
VK_B: _keys.Key.KEY_B,
VK_C: _keys.Key.KEY_C,
VK_D: _keys.Key.KEY_D,
VK_E: _keys.Key.KEY_E,
VK_F: _keys.Key.KEY_F,
VK_G: _keys.Key.KEY_G,
VK_H: _keys.Key.KEY_H,
VK_I: _keys.Key.KEY_I,
VK_J: _keys.Key.KEY_J,
VK_K: _keys.Key.KEY_K,
VK_L: _keys.Key.KEY_L,
VK_M: _keys.Key.KEY_M,
VK_N: _keys.Key.KEY_N,
VK_O: _keys.Key.KEY_O,
VK_P: _keys.Key.KEY_P,
VK_Q: _keys.Key.KEY_Q,
VK_R: _keys.Key.KEY_R,
VK_S: _keys.Key.KEY_S,
VK_T: _keys.Key.KEY_T,
VK_U: _keys.Key.KEY_U,
VK_V: _keys.Key.KEY_V,
VK_W: _keys.Key.KEY_W,
VK_X: _keys.Key.KEY_X,
VK_Y: _keys.Key.KEY_Y,
VK_Z: _keys.Key.KEY_Z,
VK_OEM_1: _keys.Key.SEMICOLON,
VK_OEM_2: _keys.Key.SLASH,
VK_OEM_3: _keys.Key.BACKQUOTE,
VK_OEM_4: _keys.Key.BRACKET_LEFT,
VK_OEM_5: _keys.Key.BACKSLASH,
VK_OEM_6: _keys.Key.BRACKET_RIGHT,
VK_OEM_7: _keys.Key.QUOTE,
VK_OEM_PLUS: _keys.Key.EQUAL,
VK_OEM_COMMA: _keys.Key.COMMA,
VK_OEM_MINUS: _keys.Key.MINUS,
VK_OEM_PERIOD: _keys.Key.PERIOD,
VK_F1: _keys.Key.F1,
VK_F2: _keys.Key.F2,
VK_F3: _keys.Key.F3,
VK_F4: _keys.Key.F4,
VK_F5: _keys.Key.F5,
VK_F6: _keys.Key.F6,
VK_F7: _keys.Key.F7,
VK_F8: _keys.Key.F8,
VK_F9: _keys.Key.F9,
VK_F10: _keys.Key.F10,
VK_F11: _keys.Key.F11,
VK_F12: _keys.Key.F12,
VK_F13: _keys.Key.F13,
VK_F14: _keys.Key.F14,
VK_F15: _keys.Key.F15,
VK_F16: _keys.Key.F16,
VK_F17: _keys.Key.F17,
VK_F18: _keys.Key.F18,
VK_F19: _keys.Key.F19,
VK_BACK: _keys.Key.BACKSPACE,
VK_TAB: _keys.Key.TAB,
VK_RETURN: _keys.Key.ENTER,
VK_CAPITAL: _keys.Key.CAPS_LOCK,
VK_ESCAPE: _keys.Key.ESCAPE,
VK_SPACE: _keys.Key.SPACE,
VK_PRIOR: _keys.Key.PAGE_UP,
VK_NEXT: _keys.Key.PAGE_DOWN,
VK_END: _keys.Key.END,
VK_HOME: _keys.Key.HOME,
VK_INSERT: _keys.Key.INSERT,
VK_DELETE: _keys.Key.DELETE,
VK_LEFT: _keys.Key.ARROW_LEFT,
VK_UP: _keys.Key.ARROW_UP,
VK_RIGHT: _keys.Key.ARROW_RIGHT,
VK_DOWN: _keys.Key.ARROW_DOWN,
VK_NUMLOCK: _keys.Key.NUM_LOCK,
VK_NUMPAD0: _keys.Key.DIGIT0,
VK_NUMPAD1: _keys.Key.DIGIT1,
VK_NUMPAD2: _keys.Key.DIGIT2,
VK_NUMPAD3: _keys.Key.DIGIT3,
VK_NUMPAD4: _keys.Key.DIGIT4,
VK_NUMPAD5: _keys.Key.DIGIT5,
VK_NUMPAD6: _keys.Key.DIGIT6,
VK_NUMPAD7: _keys.Key.DIGIT7,
VK_NUMPAD8: _keys.Key.DIGIT8,
VK_NUMPAD9: _keys.Key.DIGIT9,
VK_MULTIPLY: _keys.Key.MULTIPLY,
VK_ADD: _keys.Key.ADD,
VK_SUBTRACT: _keys.Key.SUBTRACT,
VK_DECIMAL: _keys.Key.DECIMAL,
VK_DIVIDE: _keys.Key.DIVIDE
};