Skip to content

Commit

Permalink
Release pressed keys when regaining focus in HTML5 builds (#6423)
Browse files Browse the repository at this point in the history
* Release pressed keys when regaining focus
  • Loading branch information
britzl committed Feb 21, 2022
1 parent f289b76 commit 32cf678
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions engine/glfw/js/library_glfw.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ var LibraryGLFW = {
}
},

removeEventListenerCanvas:function (type, listener, useCapture) {
if (typeof Module['canvas'] !== 'undefined') {
Module['canvas'].removeEventListener(type, listener, useCapture);
}
},
removeEventListenerCanvas:function (type, listener, useCapture) {
if (typeof Module['canvas'] !== 'undefined') {
Module['canvas'].removeEventListener(type, listener, useCapture);
}
},

isCanvasActive: function(event) {
var res = (typeof document.activeElement == 'undefined' || document.activeElement == Module["canvas"]);
Expand Down Expand Up @@ -420,6 +420,15 @@ var LibraryGLFW = {
},

onFocusChanged: function(focus) {
// If a key is pressed while the game lost focus and that key is released while
// not in focus the event will not be received for the key release. This will
// result in the key remaining in the pressed state when the game regains focus.
// To fix this we set all pressed keys to released before regaining focus.
if (focus == 1) {
for (var i = 0; i < GLFW.keys.length; i++) {
GLFW.keys[i] = 0;
}
}
if (GLFW.focusFunc) {
{{{ makeDynCall('vi', 'GLFW.focusFunc') }}}(focus);
}
Expand Down

0 comments on commit 32cf678

Please sign in to comment.