Skip to content

Commit 8f7a821

Browse files
authored
Merge pull request #157 from benptc/fix-stuck-keyboard-keys
KeyboardListener.js listens for blur events to reset key states
2 parents 9165914 + 4f92d1b commit 8f7a821

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

content_scripts/KeyboardListener.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
createNameSpace('realityEditor.device');
66

77
(function(exports) {
8-
98
class KeyboardListener {
109
constructor() {
1110
/**
@@ -118,6 +117,15 @@ createNameSpace('realityEditor.device');
118117
});
119118
}
120119
}.bind(this));
120+
121+
// reset all keys to 'up' if the window loses focus, to prevent cases where a key gets "stuck" down
122+
window.addEventListener('blur', () => {
123+
for (let code in this.keyStates) {
124+
if (this.keyStates.hasOwnProperty(code)) {
125+
this.keyStates[code] = 'up';
126+
}
127+
}
128+
});
121129
}
122130
onKeyDown(callback) {
123131
this.callbacks.onKeyDown.push(callback);

0 commit comments

Comments
 (0)