Explorar o código

Add key listeners when already focused

Poolminer %!s(int64=6) %!d(string=hai) anos
pai
achega
ac896e80b0
Modificáronse 1 ficheiros con 13 adicións e 7 borrados
  1. 13 7
      src/Inputs/scene.inputManager.ts

+ 13 - 7
src/Inputs/scene.inputManager.ts

@@ -762,13 +762,19 @@ export class InputManager {
         };
 
         // Keyboard events
-        this._onCanvasFocusObserver = engine.onCanvasFocusObservable.add(() => {
-            if (!canvas) {
-                return;
-            }
-            canvas.addEventListener("keydown", this._onKeyDown, false);
-            canvas.addEventListener("keyup", this._onKeyUp, false);
-        });
+        this._onCanvasFocusObserver = engine.onCanvasFocusObservable.add((() => {
+            let fn = () => {
+                if (!canvas) {
+                    return;
+                }
+                canvas.addEventListener("keydown", this._onKeyDown, false);
+                canvas.addEventListener("keyup", this._onKeyUp, false);
+            };
+            if (document.activeElement === canvas) {
+                fn();
+            }
+            return fn;
+        })());
 
         this._onCanvasBlurObserver = engine.onCanvasBlurObservable.add(() => {
             if (!canvas) {