Add keyboard controls for keypad and casting

This commit is contained in:
chris 2025-11-20 10:41:34 -05:00
parent b39dabfe9b
commit feec0f39fb

19
app.js
View File

@ -142,6 +142,7 @@
document.addEventListener('touchmove', handleTouchTrail, {passive: false}); document.addEventListener('touchmove', handleTouchTrail, {passive: false});
document.addEventListener('mousemove', handleMouseTrail); document.addEventListener('mousemove', handleMouseTrail);
document.addEventListener('keydown', handleKeydown);
// CHEAT LISTENER (Tap Year X 5 times) // CHEAT LISTENER (Tap Year X 5 times)
document.getElementById('level-name').addEventListener('click', () => { document.getElementById('level-name').addEventListener('click', () => {
@ -514,6 +515,24 @@
document.body.appendChild(p); setTimeout(() => p.remove(), 800); document.body.appendChild(p); setTimeout(() => p.remove(), 800);
} }
function handleKeydown(e) {
const activeEl = document.activeElement;
if (activeEl && (activeEl.tagName === 'INPUT' || activeEl.tagName === 'TEXTAREA')) return;
if (document.querySelector('.modal-overlay.visible')) return;
if (!game.active && !game.forcedAnswer) return;
const k = e.key;
if (k >= '0' && k <= '9') {
pressKey(Number(k));
} else if (k === 'Backspace') {
e.preventDefault();
pressKey('BS');
} else if (k === 'Enter') {
checkAnswer();
} else if (k === 'c' || k === 'C' || k === 'Escape') {
pressKey('C');
}
}
function openStats() { function openStats() {
game.active = false; game.active = false;
clearInterval(dementor.interval); clearInterval(dementor.interval);