@novnc/novnc 1.2.0 → 1.3.0-g0ef7582
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +0 -6
- package/README.md +16 -6
- package/core/decoders/copyrect.js +5 -0
- package/core/decoders/hextile.js +57 -3
- package/core/decoders/jpeg.js +141 -0
- package/core/decoders/raw.js +12 -2
- package/core/decoders/tight.js +24 -8
- package/core/decoders/zrle.js +185 -0
- package/core/display.js +21 -151
- package/core/encodings.js +4 -0
- package/core/input/domkeytable.js +25 -21
- package/core/input/keyboard.js +22 -127
- package/core/input/util.js +18 -35
- package/core/input/vkeys.js +0 -1
- package/core/input/xtscancodes.js +5 -3
- package/core/ra2.js +567 -0
- package/core/rfb.js +487 -171
- package/core/util/browser.js +0 -17
- package/core/util/cursor.js +1 -11
- package/core/util/events.js +0 -4
- package/core/util/md5.js +79 -0
- package/core/websock.js +76 -17
- package/docs/API.md +107 -6
- package/docs/LIBRARY.md +3 -7
- package/lib/base64.js +24 -38
- package/lib/decoders/copyrect.js +6 -11
- package/lib/decoders/hextile.js +68 -44
- package/lib/decoders/jpeg.js +146 -0
- package/lib/decoders/raw.js +14 -21
- package/lib/decoders/rre.js +3 -17
- package/lib/decoders/tight.js +43 -93
- package/lib/decoders/tightpng.js +11 -33
- package/lib/decoders/zrle.js +185 -0
- package/lib/deflator.js +9 -26
- package/lib/des.js +22 -38
- package/lib/display.js +100 -315
- package/lib/encodings.js +7 -8
- package/lib/inflator.js +6 -22
- package/lib/input/domkeytable.js +240 -208
- package/lib/input/fixedkeys.js +10 -5
- package/lib/input/gesturehandler.js +84 -154
- package/lib/input/keyboard.js +87 -238
- package/lib/input/keysym.js +16 -272
- package/lib/input/keysymdef.js +7 -9
- package/lib/input/util.js +69 -156
- package/lib/input/vkeys.js +2 -7
- package/lib/input/xtscancodes.js +10 -171
- package/lib/ra2.js +1033 -0
- package/lib/rfb.js +947 -1149
- package/lib/util/browser.js +25 -52
- package/lib/util/cursor.js +25 -81
- package/lib/util/element.js +3 -5
- package/lib/util/events.js +26 -35
- package/lib/util/eventtarget.js +4 -16
- package/lib/util/int.js +2 -3
- package/lib/util/logging.js +3 -21
- package/lib/util/md5.js +83 -0
- package/lib/util/strings.js +3 -5
- package/lib/vendor/pako/lib/utils/common.js +10 -19
- package/lib/vendor/pako/lib/zlib/adler32.js +4 -8
- package/lib/vendor/pako/lib/zlib/constants.js +4 -7
- package/lib/vendor/pako/lib/zlib/crc32.js +6 -13
- package/lib/vendor/pako/lib/zlib/deflate.js +304 -708
- package/lib/vendor/pako/lib/zlib/gzheader.js +2 -14
- package/lib/vendor/pako/lib/zlib/inffast.js +61 -177
- package/lib/vendor/pako/lib/zlib/inflate.js +421 -909
- package/lib/vendor/pako/lib/zlib/inftrees.js +66 -172
- package/lib/vendor/pako/lib/zlib/messages.js +3 -13
- package/lib/vendor/pako/lib/zlib/trees.js +250 -592
- package/lib/vendor/pako/lib/zlib/zstream.js +3 -19
- package/lib/websock.js +119 -111
- package/package.json +2 -10
- package/core/util/polyfill.js +0 -61
- package/lib/util/polyfill.js +0 -72
- package/lib/vendor/promise.js +0 -255
package/lib/input/keyboard.js
CHANGED
|
@@ -1,63 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
4
|
-
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports
|
|
9
|
-
|
|
7
|
+
exports["default"] = void 0;
|
|
10
8
|
var Log = _interopRequireWildcard(require("../util/logging.js"));
|
|
11
|
-
|
|
12
9
|
var _events = require("../util/events.js");
|
|
13
|
-
|
|
14
10
|
var KeyboardUtil = _interopRequireWildcard(require("./util.js"));
|
|
15
|
-
|
|
16
11
|
var _keysym = _interopRequireDefault(require("./keysym.js"));
|
|
17
|
-
|
|
18
12
|
var browser = _interopRequireWildcard(require("../util/browser.js"));
|
|
19
|
-
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
23
|
-
|
|
24
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
-
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
26
16
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
27
|
-
|
|
28
17
|
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, descriptor.key, descriptor); } }
|
|
29
|
-
|
|
30
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
31
|
-
|
|
18
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
32
19
|
//
|
|
33
20
|
// Keyboard event handler
|
|
34
21
|
//
|
|
35
22
|
var Keyboard = /*#__PURE__*/function () {
|
|
36
23
|
function Keyboard(target) {
|
|
37
24
|
_classCallCheck(this, Keyboard);
|
|
38
|
-
|
|
39
25
|
this._target = target || null;
|
|
40
26
|
this._keyDownList = {}; // List of depressed keys
|
|
41
27
|
// (even if they are happy)
|
|
42
|
-
|
|
43
|
-
this._pendingKey = null; // Key waiting for keypress
|
|
44
|
-
|
|
45
28
|
this._altGrArmed = false; // Windows AltGr detection
|
|
46
|
-
// keep these here so we can refer to them later
|
|
47
29
|
|
|
30
|
+
// keep these here so we can refer to them later
|
|
48
31
|
this._eventHandlers = {
|
|
49
32
|
'keyup': this._handleKeyUp.bind(this),
|
|
50
33
|
'keydown': this._handleKeyDown.bind(this),
|
|
51
|
-
'
|
|
52
|
-
|
|
53
|
-
'checkalt': this._checkAlt.bind(this)
|
|
54
|
-
}; // ===== EVENT HANDLERS =====
|
|
34
|
+
'blur': this._allKeysUp.bind(this)
|
|
35
|
+
};
|
|
55
36
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
} // ===== PRIVATE METHODS =====
|
|
37
|
+
// ===== EVENT HANDLERS =====
|
|
59
38
|
|
|
39
|
+
this.onkeyevent = function () {}; // Handler for key press/release
|
|
40
|
+
}
|
|
60
41
|
|
|
42
|
+
// ===== PRIVATE METHODS =====
|
|
61
43
|
_createClass(Keyboard, [{
|
|
62
44
|
key: "_sendKeyEvent",
|
|
63
45
|
value: function _sendKeyEvent(keysym, code, down) {
|
|
@@ -68,10 +50,8 @@ var Keyboard = /*#__PURE__*/function () {
|
|
|
68
50
|
if (!(code in this._keyDownList)) {
|
|
69
51
|
return;
|
|
70
52
|
}
|
|
71
|
-
|
|
72
53
|
delete this._keyDownList[code];
|
|
73
54
|
}
|
|
74
|
-
|
|
75
55
|
Log.Debug("onkeyevent " + (down ? "down" : "up") + ", keysym: " + keysym, ", code: " + code);
|
|
76
56
|
this.onkeyevent(keysym, code, down);
|
|
77
57
|
}
|
|
@@ -79,51 +59,45 @@ var Keyboard = /*#__PURE__*/function () {
|
|
|
79
59
|
key: "_getKeyCode",
|
|
80
60
|
value: function _getKeyCode(e) {
|
|
81
61
|
var code = KeyboardUtil.getKeycode(e);
|
|
82
|
-
|
|
83
62
|
if (code !== 'Unidentified') {
|
|
84
63
|
return code;
|
|
85
|
-
}
|
|
86
|
-
// (don't use it for 'keypress' events thought since
|
|
87
|
-
// WebKit sets it to the same as charCode)
|
|
88
|
-
|
|
64
|
+
}
|
|
89
65
|
|
|
90
|
-
|
|
66
|
+
// Unstable, but we don't have anything else to go on
|
|
67
|
+
if (e.keyCode) {
|
|
91
68
|
// 229 is used for composition events
|
|
92
69
|
if (e.keyCode !== 229) {
|
|
93
70
|
return 'Platform' + e.keyCode;
|
|
94
71
|
}
|
|
95
|
-
}
|
|
96
|
-
// is not layout independent, so it is as bad as using keyCode
|
|
97
|
-
|
|
72
|
+
}
|
|
98
73
|
|
|
74
|
+
// A precursor to the final DOM3 standard. Unfortunately it
|
|
75
|
+
// is not layout independent, so it is as bad as using keyCode
|
|
99
76
|
if (e.keyIdentifier) {
|
|
100
77
|
// Non-character key?
|
|
101
78
|
if (e.keyIdentifier.substr(0, 2) !== 'U+') {
|
|
102
79
|
return e.keyIdentifier;
|
|
103
80
|
}
|
|
104
|
-
|
|
105
81
|
var codepoint = parseInt(e.keyIdentifier.substr(2), 16);
|
|
106
|
-
var
|
|
107
|
-
return 'Platform' +
|
|
82
|
+
var _char = String.fromCharCode(codepoint).toUpperCase();
|
|
83
|
+
return 'Platform' + _char.charCodeAt();
|
|
108
84
|
}
|
|
109
|
-
|
|
110
85
|
return 'Unidentified';
|
|
111
86
|
}
|
|
112
87
|
}, {
|
|
113
88
|
key: "_handleKeyDown",
|
|
114
89
|
value: function _handleKeyDown(e) {
|
|
115
90
|
var code = this._getKeyCode(e);
|
|
91
|
+
var keysym = KeyboardUtil.getKeysym(e);
|
|
116
92
|
|
|
117
|
-
|
|
93
|
+
// Windows doesn't have a proper AltGr, but handles it using
|
|
118
94
|
// fake Ctrl+Alt. However the remote end might not be Windows,
|
|
119
95
|
// so we need to merge those in to a single AltGr event. We
|
|
120
96
|
// detect this case by seeing the two key events directly after
|
|
121
97
|
// each other with a very short time between them (<50ms).
|
|
122
|
-
|
|
123
98
|
if (this._altGrArmed) {
|
|
124
99
|
this._altGrArmed = false;
|
|
125
100
|
clearTimeout(this._altGrTimeout);
|
|
126
|
-
|
|
127
101
|
if (code === "AltRight" && e.timeStamp - this._altGrCtrlTime < 50) {
|
|
128
102
|
// FIXME: We fail to detect this if either Ctrl key is
|
|
129
103
|
// first manually pressed as Windows then no
|
|
@@ -132,194 +106,122 @@ var Keyboard = /*#__PURE__*/function () {
|
|
|
132
106
|
// even when AltGr is already down. Some
|
|
133
107
|
// browsers detect this for us though and set the
|
|
134
108
|
// key to "AltGraph".
|
|
135
|
-
keysym = _keysym
|
|
109
|
+
keysym = _keysym["default"].XK_ISO_Level3_Shift;
|
|
136
110
|
} else {
|
|
137
|
-
this._sendKeyEvent(_keysym
|
|
111
|
+
this._sendKeyEvent(_keysym["default"].XK_Control_L, "ControlLeft", true);
|
|
138
112
|
}
|
|
139
|
-
}
|
|
140
|
-
// to deal with virtual keyboards which omit key info
|
|
141
|
-
|
|
113
|
+
}
|
|
142
114
|
|
|
115
|
+
// We cannot handle keys we cannot track, but we also need
|
|
116
|
+
// to deal with virtual keyboards which omit key info
|
|
143
117
|
if (code === 'Unidentified') {
|
|
144
118
|
if (keysym) {
|
|
145
119
|
// If it's a virtual keyboard then it should be
|
|
146
120
|
// sufficient to just send press and release right
|
|
147
121
|
// after each other
|
|
148
122
|
this._sendKeyEvent(keysym, code, true);
|
|
149
|
-
|
|
150
123
|
this._sendKeyEvent(keysym, code, false);
|
|
151
124
|
}
|
|
152
|
-
|
|
153
125
|
(0, _events.stopEvent)(e);
|
|
154
126
|
return;
|
|
155
|
-
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Alt behaves more like AltGraph on macOS, so shuffle the
|
|
156
130
|
// keys around a bit to make things more sane for the remote
|
|
157
131
|
// server. This method is used by RealVNC and TigerVNC (and
|
|
158
132
|
// possibly others).
|
|
159
|
-
|
|
160
|
-
|
|
161
133
|
if (browser.isMac() || browser.isIOS()) {
|
|
162
134
|
switch (keysym) {
|
|
163
|
-
case _keysym
|
|
164
|
-
keysym = _keysym
|
|
135
|
+
case _keysym["default"].XK_Super_L:
|
|
136
|
+
keysym = _keysym["default"].XK_Alt_L;
|
|
165
137
|
break;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
keysym = _keysym.default.XK_Super_L;
|
|
138
|
+
case _keysym["default"].XK_Super_R:
|
|
139
|
+
keysym = _keysym["default"].XK_Super_L;
|
|
169
140
|
break;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
keysym = _keysym.default.XK_Mode_switch;
|
|
141
|
+
case _keysym["default"].XK_Alt_L:
|
|
142
|
+
keysym = _keysym["default"].XK_Mode_switch;
|
|
173
143
|
break;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
keysym = _keysym.default.XK_ISO_Level3_Shift;
|
|
144
|
+
case _keysym["default"].XK_Alt_R:
|
|
145
|
+
keysym = _keysym["default"].XK_ISO_Level3_Shift;
|
|
177
146
|
break;
|
|
178
147
|
}
|
|
179
|
-
}
|
|
180
|
-
// same keysym or we'll confuse the server
|
|
181
|
-
|
|
148
|
+
}
|
|
182
149
|
|
|
150
|
+
// Is this key already pressed? If so, then we must use the
|
|
151
|
+
// same keysym or we'll confuse the server
|
|
183
152
|
if (code in this._keyDownList) {
|
|
184
153
|
keysym = this._keyDownList[code];
|
|
185
|
-
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// macOS doesn't send proper key releases if a key is pressed
|
|
157
|
+
// while meta is held down
|
|
158
|
+
if ((browser.isMac() || browser.isIOS()) && e.metaKey && code !== 'MetaLeft' && code !== 'MetaRight') {
|
|
159
|
+
this._sendKeyEvent(keysym, code, true);
|
|
160
|
+
this._sendKeyEvent(keysym, code, false);
|
|
161
|
+
(0, _events.stopEvent)(e);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// macOS doesn't send proper key events for modifiers, only
|
|
186
166
|
// state change events. That gets extra confusing for CapsLock
|
|
187
167
|
// which toggles on each press, but not on release. So pretend
|
|
188
168
|
// it was a quick press and release of the button.
|
|
189
|
-
|
|
190
|
-
|
|
191
169
|
if ((browser.isMac() || browser.isIOS()) && code === 'CapsLock') {
|
|
192
|
-
this._sendKeyEvent(_keysym
|
|
193
|
-
|
|
194
|
-
this._sendKeyEvent(_keysym.default.XK_Caps_Lock, 'CapsLock', false);
|
|
195
|
-
|
|
170
|
+
this._sendKeyEvent(_keysym["default"].XK_Caps_Lock, 'CapsLock', true);
|
|
171
|
+
this._sendKeyEvent(_keysym["default"].XK_Caps_Lock, 'CapsLock', false);
|
|
196
172
|
(0, _events.stopEvent)(e);
|
|
197
173
|
return;
|
|
198
|
-
}
|
|
199
|
-
// a keypress event as well
|
|
200
|
-
// (IE and Edge has a broken KeyboardEvent.key, so we can't
|
|
201
|
-
// just check for the presence of that field)
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (!keysym && (!e.key || browser.isIE() || browser.isEdge())) {
|
|
205
|
-
this._pendingKey = code; // However we might not get a keypress event if the key
|
|
206
|
-
// is non-printable, which needs some special fallback
|
|
207
|
-
// handling
|
|
174
|
+
}
|
|
208
175
|
|
|
209
|
-
|
|
176
|
+
// Windows doesn't send proper key releases for a bunch of
|
|
177
|
+
// Japanese IM keys so we have to fake the release right away
|
|
178
|
+
var jpBadKeys = [_keysym["default"].XK_Zenkaku_Hankaku, _keysym["default"].XK_Eisu_toggle, _keysym["default"].XK_Katakana, _keysym["default"].XK_Hiragana, _keysym["default"].XK_Romaji];
|
|
179
|
+
if (browser.isWindows() && jpBadKeys.includes(keysym)) {
|
|
180
|
+
this._sendKeyEvent(keysym, code, true);
|
|
181
|
+
this._sendKeyEvent(keysym, code, false);
|
|
182
|
+
(0, _events.stopEvent)(e);
|
|
210
183
|
return;
|
|
211
184
|
}
|
|
185
|
+
(0, _events.stopEvent)(e);
|
|
212
186
|
|
|
213
|
-
|
|
214
|
-
(0, _events.stopEvent)(e); // Possible start of AltGr sequence? (see above)
|
|
215
|
-
|
|
187
|
+
// Possible start of AltGr sequence? (see above)
|
|
216
188
|
if (code === "ControlLeft" && browser.isWindows() && !("ControlLeft" in this._keyDownList)) {
|
|
217
189
|
this._altGrArmed = true;
|
|
218
190
|
this._altGrTimeout = setTimeout(this._handleAltGrTimeout.bind(this), 100);
|
|
219
191
|
this._altGrCtrlTime = e.timeStamp;
|
|
220
192
|
return;
|
|
221
193
|
}
|
|
222
|
-
|
|
223
|
-
this._sendKeyEvent(keysym, code, true);
|
|
224
|
-
} // Legacy event for browsers without code/key
|
|
225
|
-
|
|
226
|
-
}, {
|
|
227
|
-
key: "_handleKeyPress",
|
|
228
|
-
value: function _handleKeyPress(e) {
|
|
229
|
-
(0, _events.stopEvent)(e); // Are we expecting a keypress?
|
|
230
|
-
|
|
231
|
-
if (this._pendingKey === null) {
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
var code = this._getKeyCode(e);
|
|
236
|
-
|
|
237
|
-
var keysym = KeyboardUtil.getKeysym(e); // The key we were waiting for?
|
|
238
|
-
|
|
239
|
-
if (code !== 'Unidentified' && code != this._pendingKey) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
code = this._pendingKey;
|
|
244
|
-
this._pendingKey = null;
|
|
245
|
-
|
|
246
|
-
if (!keysym) {
|
|
247
|
-
Log.Info('keypress with no keysym:', e);
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
this._sendKeyEvent(keysym, code, true);
|
|
252
|
-
}
|
|
253
|
-
}, {
|
|
254
|
-
key: "_handleKeyPressTimeout",
|
|
255
|
-
value: function _handleKeyPressTimeout(e) {
|
|
256
|
-
// Did someone manage to sort out the key already?
|
|
257
|
-
if (this._pendingKey === null) {
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
var keysym;
|
|
262
|
-
var code = this._pendingKey;
|
|
263
|
-
this._pendingKey = null; // We have no way of knowing the proper keysym with the
|
|
264
|
-
// information given, but the following are true for most
|
|
265
|
-
// layouts
|
|
266
|
-
|
|
267
|
-
if (e.keyCode >= 0x30 && e.keyCode <= 0x39) {
|
|
268
|
-
// Digit
|
|
269
|
-
keysym = e.keyCode;
|
|
270
|
-
} else if (e.keyCode >= 0x41 && e.keyCode <= 0x5a) {
|
|
271
|
-
// Character (A-Z)
|
|
272
|
-
var char = String.fromCharCode(e.keyCode); // A feeble attempt at the correct case
|
|
273
|
-
|
|
274
|
-
if (e.shiftKey) {
|
|
275
|
-
char = char.toUpperCase();
|
|
276
|
-
} else {
|
|
277
|
-
char = char.toLowerCase();
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
keysym = char.charCodeAt();
|
|
281
|
-
} else {
|
|
282
|
-
// Unknown, give up
|
|
283
|
-
keysym = 0;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
194
|
this._sendKeyEvent(keysym, code, true);
|
|
287
195
|
}
|
|
288
196
|
}, {
|
|
289
197
|
key: "_handleKeyUp",
|
|
290
198
|
value: function _handleKeyUp(e) {
|
|
291
199
|
(0, _events.stopEvent)(e);
|
|
200
|
+
var code = this._getKeyCode(e);
|
|
292
201
|
|
|
293
|
-
|
|
202
|
+
// We can't get a release in the middle of an AltGr sequence, so
|
|
294
203
|
// abort that detection
|
|
295
|
-
|
|
296
|
-
|
|
297
204
|
if (this._altGrArmed) {
|
|
298
205
|
this._altGrArmed = false;
|
|
299
206
|
clearTimeout(this._altGrTimeout);
|
|
207
|
+
this._sendKeyEvent(_keysym["default"].XK_Control_L, "ControlLeft", true);
|
|
208
|
+
}
|
|
300
209
|
|
|
301
|
-
|
|
302
|
-
} // See comment in _handleKeyDown()
|
|
303
|
-
|
|
304
|
-
|
|
210
|
+
// See comment in _handleKeyDown()
|
|
305
211
|
if ((browser.isMac() || browser.isIOS()) && code === 'CapsLock') {
|
|
306
|
-
this._sendKeyEvent(_keysym
|
|
307
|
-
|
|
308
|
-
this._sendKeyEvent(_keysym.default.XK_Caps_Lock, 'CapsLock', false);
|
|
309
|
-
|
|
212
|
+
this._sendKeyEvent(_keysym["default"].XK_Caps_Lock, 'CapsLock', true);
|
|
213
|
+
this._sendKeyEvent(_keysym["default"].XK_Caps_Lock, 'CapsLock', false);
|
|
310
214
|
return;
|
|
311
215
|
}
|
|
216
|
+
this._sendKeyEvent(this._keyDownList[code], code, false);
|
|
312
217
|
|
|
313
|
-
|
|
218
|
+
// Windows has a rather nasty bug where it won't send key
|
|
314
219
|
// release events for a Shift button if the other Shift is still
|
|
315
220
|
// pressed
|
|
316
|
-
|
|
317
|
-
|
|
318
221
|
if (browser.isWindows() && (code === 'ShiftLeft' || code === 'ShiftRight')) {
|
|
319
222
|
if ('ShiftRight' in this._keyDownList) {
|
|
320
223
|
this._sendKeyEvent(this._keyDownList['ShiftRight'], 'ShiftRight', false);
|
|
321
224
|
}
|
|
322
|
-
|
|
323
225
|
if ('ShiftLeft' in this._keyDownList) {
|
|
324
226
|
this._sendKeyEvent(this._keyDownList['ShiftLeft'], 'ShiftLeft', false);
|
|
325
227
|
}
|
|
@@ -330,100 +232,47 @@ var Keyboard = /*#__PURE__*/function () {
|
|
|
330
232
|
value: function _handleAltGrTimeout() {
|
|
331
233
|
this._altGrArmed = false;
|
|
332
234
|
clearTimeout(this._altGrTimeout);
|
|
333
|
-
|
|
334
|
-
this._sendKeyEvent(_keysym.default.XK_Control_L, "ControlLeft", true);
|
|
235
|
+
this._sendKeyEvent(_keysym["default"].XK_Control_L, "ControlLeft", true);
|
|
335
236
|
}
|
|
336
237
|
}, {
|
|
337
238
|
key: "_allKeysUp",
|
|
338
239
|
value: function _allKeysUp() {
|
|
339
240
|
Log.Debug(">> Keyboard.allKeysUp");
|
|
340
|
-
|
|
341
241
|
for (var code in this._keyDownList) {
|
|
342
242
|
this._sendKeyEvent(this._keyDownList[code], code, false);
|
|
343
243
|
}
|
|
344
|
-
|
|
345
244
|
Log.Debug("<< Keyboard.allKeysUp");
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
}, {
|
|
349
|
-
key: "_checkAlt",
|
|
350
|
-
value: function _checkAlt(e) {
|
|
351
|
-
if (e.skipCheckAlt) {
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
if (e.altKey) {
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
var target = this._target;
|
|
360
|
-
var downList = this._keyDownList;
|
|
361
|
-
['AltLeft', 'AltRight'].forEach(function (code) {
|
|
362
|
-
if (!(code in downList)) {
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
var event = new KeyboardEvent('keyup', {
|
|
367
|
-
key: downList[code],
|
|
368
|
-
code: code
|
|
369
|
-
});
|
|
370
|
-
event.skipCheckAlt = true;
|
|
371
|
-
target.dispatchEvent(event);
|
|
372
|
-
});
|
|
373
|
-
} // ===== PUBLIC METHODS =====
|
|
245
|
+
}
|
|
374
246
|
|
|
247
|
+
// ===== PUBLIC METHODS =====
|
|
375
248
|
}, {
|
|
376
249
|
key: "grab",
|
|
377
250
|
value: function grab() {
|
|
378
251
|
//Log.Debug(">> Keyboard.grab");
|
|
379
|
-
this._target.addEventListener('keydown', this._eventHandlers.keydown);
|
|
380
252
|
|
|
253
|
+
this._target.addEventListener('keydown', this._eventHandlers.keydown);
|
|
381
254
|
this._target.addEventListener('keyup', this._eventHandlers.keyup);
|
|
382
255
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
window.addEventListener('blur', this._eventHandlers.blur); // Firefox on Windows has broken handling of Alt, so we need to
|
|
387
|
-
// poll as best we can for releases (still doesn't prevent the
|
|
388
|
-
// menu from popping up though as we can't call
|
|
389
|
-
// preventDefault())
|
|
390
|
-
|
|
391
|
-
if (browser.isWindows() && browser.isFirefox()) {
|
|
392
|
-
var handler = this._eventHandlers.checkalt;
|
|
393
|
-
['mousedown', 'mouseup', 'mousemove', 'wheel', 'touchstart', 'touchend', 'touchmove', 'keydown', 'keyup'].forEach(function (type) {
|
|
394
|
-
return document.addEventListener(type, handler, {
|
|
395
|
-
capture: true,
|
|
396
|
-
passive: true
|
|
397
|
-
});
|
|
398
|
-
});
|
|
399
|
-
} //Log.Debug("<< Keyboard.grab");
|
|
256
|
+
// Release (key up) if window loses focus
|
|
257
|
+
window.addEventListener('blur', this._eventHandlers.blur);
|
|
400
258
|
|
|
259
|
+
//Log.Debug("<< Keyboard.grab");
|
|
401
260
|
}
|
|
402
261
|
}, {
|
|
403
262
|
key: "ungrab",
|
|
404
263
|
value: function ungrab() {
|
|
405
264
|
//Log.Debug(">> Keyboard.ungrab");
|
|
406
|
-
if (browser.isWindows() && browser.isFirefox()) {
|
|
407
|
-
var handler = this._eventHandlers.checkalt;
|
|
408
|
-
['mousedown', 'mouseup', 'mousemove', 'wheel', 'touchstart', 'touchend', 'touchmove', 'keydown', 'keyup'].forEach(function (type) {
|
|
409
|
-
return document.removeEventListener(type, handler);
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
265
|
|
|
413
266
|
this._target.removeEventListener('keydown', this._eventHandlers.keydown);
|
|
414
|
-
|
|
415
267
|
this._target.removeEventListener('keyup', this._eventHandlers.keyup);
|
|
268
|
+
window.removeEventListener('blur', this._eventHandlers.blur);
|
|
416
269
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
window.removeEventListener('blur', this._eventHandlers.blur); // Release (key up) all keys that are in a down state
|
|
420
|
-
|
|
421
|
-
this._allKeysUp(); //Log.Debug(">> Keyboard.ungrab");
|
|
270
|
+
// Release (key up) all keys that are in a down state
|
|
271
|
+
this._allKeysUp();
|
|
422
272
|
|
|
273
|
+
//Log.Debug(">> Keyboard.ungrab");
|
|
423
274
|
}
|
|
424
275
|
}]);
|
|
425
|
-
|
|
426
276
|
return Keyboard;
|
|
427
277
|
}();
|
|
428
|
-
|
|
429
|
-
exports.default = Keyboard;
|
|
278
|
+
exports["default"] = Keyboard;
|