From baab6e8ac2ff4215e6d57765c992b67134572dce Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sun, 13 Dec 2020 02:51:22 +0100 Subject: [PATCH] In web client, enable keyboard control except if in outer HTML input field. --- rogue_chat.html | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/rogue_chat.html b/rogue_chat.html index 0ba8cf0..0738740 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -16,9 +16,6 @@ terminal rows:

 
-
-keyboard input/control: -

button controls for hard-to-remember keybindings

@@ -1512,7 +1509,9 @@ tui.inputEl.addEventListener('input', (event) => { tui.full_refresh(); }, false); document.onclick = function() { - tui.show_help = false; + if (!tui.mode.is_single_char_entry) { + tui.show_help = false; + } }; tui.inputEl.addEventListener('keydown', (event) => { tui.show_help = false; @@ -1715,18 +1714,9 @@ window.setInterval(function() { } }, 1000); window.setInterval(function() { - let val = "?"; - let span_decoration = "none"; - if (document.activeElement == tui.inputEl) { - val = "on (click outside terminal to change)"; - } else { - val = "off (click into terminal to change)"; - span_decoration = "line-through"; + if (document.activeElement.tagName.toLowerCase() != 'input') { + tui.inputEl.focus(); }; - document.getElementById("keyboard_control").textContent = val; - for (const span of document.querySelectorAll('.keyboard_controlled')) { - span.style.textDecoration = span_decoration; - } }, 100); document.getElementById("terminal").onclick = function() { tui.inputEl.focus(); @@ -1775,14 +1765,20 @@ for (const move_button of document.querySelectorAll('[id*="_move_"]')) { continue; }; let direction = move_button.id.split('_')[2].toUpperCase(); - move_button.onclick = function() { - if (tui.mode.available_actions.includes("move")) { - server.send(['TASK:MOVE', direction]); - } else if (tui.mode.available_actions.includes("move_explorer")) { - explorer.move(direction); - tui.full_refresh(); - }; + let move_repeat; + move_button.onmousedown = function() { + move_repeat = window.setInterval(function() { + if (tui.mode.available_actions.includes("move")) { + server.send(['TASK:MOVE', direction]); + } else if (tui.mode.available_actions.includes("move_explorer")) { + explorer.move(direction); + tui.full_refresh(); + }; + }, 100); }; + move_button.onmouseup = function() { + window.clearInterval(move_repeat); + } }; -- 2.30.2