From c558b814711a0b770a0a71f97d7d08cdb898d09b Mon Sep 17 00:00:00 2001 From: mrhid6 Date: Mon, 20 Jul 2026 09:42:07 +0100 Subject: [PATCH] fix: Fixed keyboard disconnect --- web/lib/guacConsole.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/web/lib/guacConsole.ts b/web/lib/guacConsole.ts index e118656..66af968 100644 --- a/web/lib/guacConsole.ts +++ b/web/lib/guacConsole.ts @@ -14,6 +14,8 @@ export function openConsole( container.innerHTML = ""; container.appendChild(client.getDisplay().getElement()); + // Make the console focusable so keyboard capture is scoped to it (see below). + container.tabIndex = 0; client.connect(connectData); @@ -37,12 +39,20 @@ export function openConsole( ); client.sendMouseState(s); }; - const keyboard = new Guacamole.Keyboard(document); + // Scope keyboard capture to the container rather than `document`, so it only + // grabs keys while the console is focused and stops entirely once the element + // is removed (navigating away / disconnect). Attaching to `document` leaks the + // capture and swallows keystrokes in unrelated inputs. + const keyboard = new Guacamole.Keyboard(container); keyboard.onkeydown = (k: number) => client.sendKeyEvent(1, k); keyboard.onkeyup = (k: number) => client.sendKeyEvent(0, k); + container.focus(); return { disconnect() { + keyboard.onkeydown = null; + keyboard.onkeyup = null; + if (typeof keyboard.reset === "function") keyboard.reset(); client.disconnect(); }, setScale(s: number) {