From 065e37342aa0959f4465d8e2c3f5b7578d9f9fe0 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien <77750390+ethanaobrien@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:32:27 -0600 Subject: [PATCH] Add EJS_noAutoFocus --- data/emulator.js | 6 +++--- data/loader.js | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/data/emulator.js b/data/emulator.js index 5e5578d..27372a8 100644 --- a/data/emulator.js +++ b/data/emulator.js @@ -1128,7 +1128,7 @@ class EmulatorJS { this.updateCheatUI(); this.updateGamepadLabels(); if (!this.muted) this.setVolume(this.volume); - this.elements.parent.focus(); + if (this.config.noAutoFocus !== true) this.elements.parent.focus(); this.textElem.remove(); this.textElem = null; this.game.classList.remove("ejs_game"); @@ -1196,7 +1196,7 @@ class EmulatorJS { this.setVirtualGamepad(); this.addEventListener(this.elements.parent, "keydown keyup", this.keyChange.bind(this)); this.addEventListener(this.elements.parent, "mousedown touchstart", (e) => { - if (document.activeElement !== this.elements.parent) this.elements.parent.focus(); + if (document.activeElement !== this.elements.parent && this.config.noAutoFocus !== true) this.elements.parent.focus(); }) this.addEventListener(window, "resize", this.handleResize.bind(this)); //this.addEventListener(window, "blur", e => console.log(e), true); //TODO - add "click to make keyboard keys work" message? @@ -1211,7 +1211,7 @@ class EmulatorJS { this.addEventListener(window, "webkitfullscreenchange mozfullscreenchange fullscreenchange MSFullscreenChange", () => { setTimeout(() => { this.handleResize.bind(this); - this.elements.parent.focus(); + if (this.config.noAutoFocus !== true) this.elements.parent.focus(); }, 0); }); this.addEventListener(this.elements.parent, "dragenter", (e) => { diff --git a/data/loader.js b/data/loader.js index 5681c85..582043d 100644 --- a/data/loader.js +++ b/data/loader.js @@ -112,6 +112,7 @@ config.disableDatabases = window.EJS_disableDatabases; config.disableLocalStorage = window.EJS_disableLocalStorage; config.forceLegacyCores = window.EJS_forceLegacyCores; + config.noAutoFocus = window.EJS_noAutoFocus; if (typeof window.EJS_language === "string" && window.EJS_language !== "en-US") { try {