diff options
author | Pierre Ossman <ossman@cendio.se> | 2019-11-01 13:13:35 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2019-11-01 13:13:35 +0100 |
commit | 3388c92c7f55b4e77527d1481a52c27459345f46 (patch) | |
tree | c08ad25a8387c170008d3011d0d418fa28aa28e3 | |
parent | 1096555414b060510132805a6ac3718758997476 (diff) | |
download | novnc-3388c92c7f55b4e77527d1481a52c27459345f46.tar.gz |
Send NumLock on macOS, even though the key is Clear
There is no obvious choice what works best here, but this is what
TigerVNC has been doing for years without complaints. Let's follow
them until we get reports that this doesn't work well.
-rw-r--r-- | core/input/util.js | 17 | ||||
-rw-r--r-- | tests/test.helper.js | 10 |
2 files changed, 27 insertions, 0 deletions
diff --git a/core/input/util.js b/core/input/util.js index f0172c9..1b98040 100644 --- a/core/input/util.js +++ b/core/input/util.js @@ -156,6 +156,14 @@ export function getKeysym(evt) { location = 2; } + // And for Clear + if ((key === 'Clear') && (location === 3)) { + let code = getKeycode(evt); + if (code === 'NumLock') { + location = 0; + } + } + if ((location === undefined) || (location > 3)) { location = 0; } @@ -172,6 +180,15 @@ export function getKeysym(evt) { } } + // macOS has Clear instead of NumLock, but the remote system is + // probably not macOS, so lying here is probably best... + if (key === 'Clear') { + let code = getKeycode(evt); + if (code === 'NumLock') { + return KeyTable.XK_Num_Lock; + } + } + return DOMKeyTable[key][location]; } diff --git a/tests/test.helper.js b/tests/test.helper.js index 7d4b011..0232819 100644 --- a/tests/test.helper.js +++ b/tests/test.helper.js @@ -205,12 +205,22 @@ describe('Helpers', function () { expect(KeyboardUtil.getKeysym({code: 'AltRight', key: 'Alt', location: 2})).to.be.equal(0xFFEA); expect(KeyboardUtil.getKeysym({code: 'AltRight', key: 'AltGraph', location: 2})).to.be.equal(0xFE03); }); + it('should handle Windows key with incorrect location', function () { + expect(KeyboardUtil.getKeysym({key: 'Meta', location: 0})).to.be.equal(0xFFEC); + }); + it('should handle Clear/NumLock key with incorrect location', function () { + this.skip(); // Broken because of Clear/NumLock override + expect(KeyboardUtil.getKeysym({key: 'Clear', code: 'NumLock', location: 3})).to.be.equal(0xFF0B); + }); it('should handle Meta/Windows distinction', function () { expect(KeyboardUtil.getKeysym({code: 'AltLeft', key: 'Meta', location: 1})).to.be.equal(0xFFE7); expect(KeyboardUtil.getKeysym({code: 'AltRight', key: 'Meta', location: 2})).to.be.equal(0xFFE8); expect(KeyboardUtil.getKeysym({code: 'MetaLeft', key: 'Meta', location: 1})).to.be.equal(0xFFEB); expect(KeyboardUtil.getKeysym({code: 'MetaRight', key: 'Meta', location: 2})).to.be.equal(0xFFEC); }); + it('should send NumLock even if key is Clear', function () { + expect(KeyboardUtil.getKeysym({key: 'Clear', code: 'NumLock'})).to.be.equal(0xFF7F); + }); it('should return null for unknown keys', function () { expect(KeyboardUtil.getKeysym({key: 'Semicolon'})).to.be.null; expect(KeyboardUtil.getKeysym({key: 'BracketRight'})).to.be.null; |