From ab2fd4169348e968ddf60b3334dcbe3b377e7cbc Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 23 Jan 2024 12:51:35 +0100 Subject: [PATCH] Handle broken Oculus browser keyboard events It sets KeyboardEvent.key to "Unidentified" for all non-character keys, which means we must ignore it and use the legacy handling to figure out the key pressed. --- core/input/util.js | 2 +- tests/test.helper.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core/input/util.js b/core/input/util.js index 58f84e55..36b69817 100644 --- a/core/input/util.js +++ b/core/input/util.js @@ -67,7 +67,7 @@ export function getKeycode(evt) { // Get 'KeyboardEvent.key', handling legacy browsers export function getKey(evt) { // Are we getting a proper key value? - if (evt.key !== undefined) { + if ((evt.key !== undefined) && (evt.key !== 'Unidentified')) { // Mozilla isn't fully in sync with the spec yet switch (evt.key) { case 'OS': return 'Meta'; diff --git a/tests/test.helper.js b/tests/test.helper.js index ff83c539..9995973f 100644 --- a/tests/test.helper.js +++ b/tests/test.helper.js @@ -108,6 +108,8 @@ describe('Helpers', function () { }); it('should use charCode if no key', function () { expect(KeyboardUtil.getKey({charCode: 'Š'.charCodeAt(), keyCode: 0x42, which: 0x43})).to.be.equal('Š'); + // Broken Oculus browser + expect(KeyboardUtil.getKey({charCode: 'Š'.charCodeAt(), keyCode: 0x42, which: 0x43, key: 'Unidentified'})).to.be.equal('Š'); }); it('should return Unidentified when it cannot map the key', function () { expect(KeyboardUtil.getKey({keycode: 0x42})).to.be.equal('Unidentified');