From 2da27695b2e5d8fd7613371f1c7aa706d34aafae Mon Sep 17 00:00:00 2001 From: ijlal99 Date: Fri, 3 Jan 2025 23:55:51 +0500 Subject: [PATCH] XEOK-171: CameraControl stops reacting when using system shortcuts --- .../lib/handlers/KeyboardPanRotateDollyHandler.js | 10 ++++++++++ .../lib/handlers/MousePanRotateDollyHandler.js | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/viewer/scene/CameraControl/lib/handlers/KeyboardPanRotateDollyHandler.js b/src/viewer/scene/CameraControl/lib/handlers/KeyboardPanRotateDollyHandler.js index 3ddb7ad6d..4911f1ab0 100644 --- a/src/viewer/scene/CameraControl/lib/handlers/KeyboardPanRotateDollyHandler.js +++ b/src/viewer/scene/CameraControl/lib/handlers/KeyboardPanRotateDollyHandler.js @@ -39,6 +39,14 @@ class KeyboardPanRotateDollyHandler { } }); + document.addEventListener("visibilitychange", this._onVisibilityChange = () => { + keyDownMap.splice(0); + }) + + window.addEventListener("blur", this._onBlur = () => { + keyDownMap.splice(0); + }) + this._onTick = scene.on("tick", (e) => { if (!(configs.active && configs.pointerEnabled) || (!scene.input.keyboardEnabled)) { @@ -168,6 +176,8 @@ class KeyboardPanRotateDollyHandler { this._scene.input.off(this._onSceneMouseMove); this._scene.input.off(this._onSceneKeyDown); + document.removeEventListener("visibilitychange", this._onVisibilityChange); + window.removeEventListener("blur", this._onBlur); this._scene.input.off(this._onSceneKeyUp); } } diff --git a/src/viewer/scene/CameraControl/lib/handlers/MousePanRotateDollyHandler.js b/src/viewer/scene/CameraControl/lib/handlers/MousePanRotateDollyHandler.js index cdbaf7426..43c8edcca 100644 --- a/src/viewer/scene/CameraControl/lib/handlers/MousePanRotateDollyHandler.js +++ b/src/viewer/scene/CameraControl/lib/handlers/MousePanRotateDollyHandler.js @@ -77,6 +77,14 @@ class MousePanRotateDollyHandler { keyDown[keyCode] = false; }); + document.addEventListener("visibilitychange", this._onVisibilityChange = () => { + keyDown.splice(0); + }) + + window.addEventListener("blur", this._onBlur = () => { + keyDown.splice(0); + }) + function setMousedownState(pick = true) { setMousedownPositions(); if (pick) { @@ -355,6 +363,8 @@ class MousePanRotateDollyHandler { document.removeEventListener("keydown", this._documentKeyDownHandler); document.removeEventListener("keyup", this._documentKeyUpHandler); + document.removeEventListener("visibilitychange", this._onVisibilityChange); + window.removeEventListener("blur", this._onBlur); canvas.removeEventListener("mousedown", this._mouseDownHandler); document.removeEventListener("mousemove", this._documentMouseMoveHandler); canvas.removeEventListener("mousemove", this._canvasMouseMoveHandler);