summaryrefslogtreecommitdiff
path: root/platform/javascript/js
diff options
context:
space:
mode:
Diffstat (limited to 'platform/javascript/js')
-rw-r--r--platform/javascript/js/libs/library_godot_input.js18
1 files changed, 16 insertions, 2 deletions
diff --git a/platform/javascript/js/libs/library_godot_input.js b/platform/javascript/js/libs/library_godot_input.js
index 587c320f35..3c1c05e44e 100644
--- a/platform/javascript/js/libs/library_godot_input.js
+++ b/platform/javascript/js/libs/library_godot_input.js
@@ -104,10 +104,14 @@ const GodotInputGamepads = {
}
}
GodotEventListeners.add(window, 'gamepadconnected', function (evt) {
- add(evt.gamepad);
+ if (evt.gamepad) {
+ add(evt.gamepad);
+ }
}, false);
GodotEventListeners.add(window, 'gamepaddisconnected', function (evt) {
- onchange(evt.gamepad.index, 0);
+ if (evt.gamepad) {
+ onchange(evt.gamepad.index, 0);
+ }
}, false);
},
@@ -389,6 +393,11 @@ const GodotInput = {
const rect = canvas.getBoundingClientRect();
const pos = GodotInput.computePosition(evt, rect);
const modifiers = GodotInput.getModifiers(evt);
+ // Since the event is consumed, focus manually.
+ // NOTE: The iframe container may not have focus yet, so focus even when already active.
+ if (p_pressed) {
+ GodotConfig.canvas.focus();
+ }
if (func(p_pressed, evt.button, pos[0], pos[1], modifiers)) {
evt.preventDefault();
}
@@ -405,6 +414,11 @@ const GodotInput = {
const func = GodotRuntime.get_func(callback);
const canvas = GodotConfig.canvas;
function touch_cb(type, evt) {
+ // Since the event is consumed, focus manually.
+ // NOTE: The iframe container may not have focus yet, so focus even when already active.
+ if (type === 0) {
+ GodotConfig.canvas.focus();
+ }
const rect = canvas.getBoundingClientRect();
const touches = evt.changedTouches;
for (let i = 0; i < touches.length; i++) {