Skip to content

Commit

Permalink
Handle broken Oculus browser keyboard events
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
CendioOssman committed Jan 23, 2024
1 parent fca48df commit ab2fd41
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/input/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions tests/test.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit ab2fd41

Please sign in to comment.