Skip to content

Commit

Permalink
Make the game playable with the keyboard
Browse files Browse the repository at this point in the history
Co-Authored-By: Lea Verou <[email protected]>
  • Loading branch information
DmitrySharabin and LeaVerou committed Sep 16, 2024
1 parent 457d690 commit b55e10d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ <h1 aria-label="Mavordle">
<button mv-list-item mv-group
mv-action="if(guessLength < 5, add(group('letter': key), usedLetters) & add(key, guessLetters))"
mv-attribute="none"
id="key-[key]"
class="[if(attempt > 1, if(contains(join(guesses), key), if(key in correctLetters, correct, if(contains(hiddenWord, key), elsewhere, absent))))]"
style="--row: [row]"
disabled="[isOver]">[key]</button>
Expand Down Expand Up @@ -236,6 +237,23 @@ <h2>Next Mavordle</h2>
</section>
</footer>

<script>
// Make the game playable with the keyboard
document.addEventListener("keyup", event => {
let key = document.getElementById("key-" + event.key.toLowerCase());
if (key) {
event.preventDefault();
key.click();
}
else if (event.key === "Enter") {
document.getElementById("enter").click();
}
else if (event.key === "Backspace") {
document.getElementById("bs").click();
}
});
</script>

</body>

</html>

0 comments on commit b55e10d

Please sign in to comment.