keyboard-shortcuts.js (1505B)
1 /** 2 * Keyboard Shortcuts 3 * Atalhos para acelerar a navegação e resposta de quizzes 4 * 5 * Atalhos: 6 * 1-5: Selecionar opção A-E 7 * Espaço: Próxima questão 8 * Esc: Fechar notas/floaters 9 * ?: Mostrar ajuda 10 */ 11 12 const SHORTCUTS = { 13 '1': () => selectOptionByLetter(0), 14 '2': () => selectOptionByLetter(1), 15 '3': () => selectOptionByLetter(2), 16 '4': () => selectOptionByLetter(3), 17 '5': () => selectOptionByLetter(4), 18 ' ': (e) => { 19 e.preventDefault(); 20 const nextBtn = document.getElementById('btn-next'); 21 if (nextBtn && nextBtn.style.display !== 'none') { 22 nextBtn.click(); 23 } 24 }, 25 'Escape': () => { 26 // Fechar floaters se existir 27 if (typeof closeFloater === 'function') { 28 closeFloater(); 29 } 30 }, 31 '?': (e) => { 32 e.preventDefault(); 33 showKeyboardHelp(); 34 }, 35 }; 36 37 function selectOptionByLetter(index) { 38 const buttons = document.querySelectorAll('.opt'); 39 if (buttons[index]) { 40 buttons[index].click(); 41 } 42 } 43 44 function showKeyboardHelp() { 45 const help = ` 46 ⌨️ Atalhos de Teclado 47 48 Quizzes: 49 1-5 Selecionar opção A-E 50 SPC Próxima questão 51 ESC Fechar notas 52 53 Geral: 54 ESC Fechar floaters 55 ? Mostrar esta ajuda 56 `; 57 58 alert(help); 59 } 60 61 document.addEventListener('keydown', (e) => { 62 // Ignorar se está digitando em um input/textarea 63 if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') { 64 return; 65 } 66 67 const key = e.key; 68 const handler = SHORTCUTS[key]; 69 70 if (handler) { 71 handler(e); 72 } 73 });