From 1c32276b45996f9a04a6f4e29625148bf678b5bb Mon Sep 17 00:00:00 2001 From: RiskoZoSlovenska Date: Thu, 26 Oct 2023 19:13:52 -0400 Subject: [PATCH] Hangman: Don't read keypresses when not focused --- files/assets/scripts/hangman.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/files/assets/scripts/hangman.js b/files/assets/scripts/hangman.js index e9d47d2..0da2182 100644 --- a/files/assets/scripts/hangman.js +++ b/files/assets/scripts/hangman.js @@ -261,6 +261,10 @@ function fetchWords() { function bindButtonToKeystroke(button, key) { document.addEventListener("keydown", event => { + if (!document.activeElement.contains(button) && !BUTTON_CONTAINER.contains(document.activeElement)) { + return; + } + if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey || event.isComposing) { return } else if (event.key.toUpperCase() == key.toUpperCase()) {