window.addEventListener('keydown', e => { const k = e.key; const a = KEYMAP[k] || (k.length === 1 ? KEYMAP[k.toLowerCase()] : null); if (!a) return; if (k === ' ' || k.indexOf('Arrow') === 0) e.preventDefault(); // 开始 / 重来 if (a === 'start' || ((state === 'ready' || state === 'over') && a === 'hard')){ if (state === 'ready' || state === 'over'){ startGame(); return; } return; } if (a === 'pause'){ togglePause(); return; } if (e.repeat && (a === 'cw' || a === 'ccw' || a === 'hold' || a === 'hard')) return; if (state !== 'playing') return; act(a); }, {passive: false});