Skip to content

Commit

Permalink
Hangman: Don't read keypresses when not focused
Browse files Browse the repository at this point in the history
  • Loading branch information
RiskoZoSlovenska committed Oct 26, 2023
1 parent 237e89a commit 1c32276
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions files/assets/scripts/hangman.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 1c32276

Please sign in to comment.