From a8dc933701c97e6ae82233e03196625d8507fc4a Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 1 Nov 2019 09:59:02 +0100 Subject: [PATCH] Fix AltGr for a few more keys in IE and Edge Some keys apparently send 'Unidentified' rather than an unshifted value. Make sure those are also handled. Examples are \ and | on a Swedish keyboard. --- kasmweb/core/input/util.js | 13 ++++++++++--- kasmweb/tests/test.helper.js | 10 ++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/kasmweb/core/input/util.js b/kasmweb/core/input/util.js index b0e8855..d93aafa 100644 --- a/kasmweb/core/input/util.js +++ b/kasmweb/core/input/util.js @@ -108,9 +108,16 @@ export function getKey(evt) { return 'Delete'; } - // IE and Edge have broken handling of AltGraph so we cannot - // trust them for printable characters - if ((evt.key.length !== 1) || (!browser.isIE() && !browser.isEdge())) { + // IE and Edge need special handling, but for everyone else we + // can trust the value provided + if (!browser.isIE() && !browser.isEdge()) { + return evt.key; + } + + // IE and Edge have broken handling of AltGraph so we can only + // trust them for non-printable characters (and unfortunately + // they also specify 'Unidentified' for some problem keys) + if ((evt.key.length !== 1) && (evt.key !== 'Unidentified')) { return evt.key; } } diff --git a/kasmweb/tests/test.helper.js b/kasmweb/tests/test.helper.js index 70eba1b..7d4b011 100644 --- a/kasmweb/tests/test.helper.js +++ b/kasmweb/tests/test.helper.js @@ -169,6 +169,16 @@ describe('Helpers', function () { window.navigator.userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"; expect(KeyboardUtil.getKey({key: 'Shift'})).to.be.equal('Shift'); }); + it('should allow printable character key with charCode on IE', function () { + window.navigator.userAgent = "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko"; + expect(KeyboardUtil.getKey({key: 'a', charCode: 0x61})).to.be.equal('a'); + expect(KeyboardUtil.getKey({key: 'Unidentified', charCode: 0x61})).to.be.equal('a'); + }); + it('should allow printable character key with charCode on Edge', function () { + window.navigator.userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"; + expect(KeyboardUtil.getKey({key: 'a', charCode: 0x61})).to.be.equal('a'); + expect(KeyboardUtil.getKey({key: 'Unidentified', charCode: 0x61})).to.be.equal('a'); + }); }); });