From 7316238f16655bd127b04476bbf7864b27f940f9 Mon Sep 17 00:00:00 2001 From: Sivaldo Date: Sat, 13 Jun 2026 19:20:23 -0300 Subject: Commit inicial --- static/keyboard-shortcuts.js | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 static/keyboard-shortcuts.js (limited to 'static/keyboard-shortcuts.js') diff --git a/static/keyboard-shortcuts.js b/static/keyboard-shortcuts.js new file mode 100644 index 0000000..53cfe44 --- /dev/null +++ b/static/keyboard-shortcuts.js @@ -0,0 +1,73 @@ +/** + * Keyboard Shortcuts + * Atalhos para acelerar a navegação e resposta de quizzes + * + * Atalhos: + * 1-5: Selecionar opção A-E + * Espaço: Próxima questão + * Esc: Fechar notas/floaters + * ?: Mostrar ajuda + */ + +const SHORTCUTS = { + '1': () => selectOptionByLetter(0), + '2': () => selectOptionByLetter(1), + '3': () => selectOptionByLetter(2), + '4': () => selectOptionByLetter(3), + '5': () => selectOptionByLetter(4), + ' ': (e) => { + e.preventDefault(); + const nextBtn = document.getElementById('btn-next'); + if (nextBtn && nextBtn.style.display !== 'none') { + nextBtn.click(); + } + }, + 'Escape': () => { + // Fechar floaters se existir + if (typeof closeFloater === 'function') { + closeFloater(); + } + }, + '?': (e) => { + e.preventDefault(); + showKeyboardHelp(); + }, +}; + +function selectOptionByLetter(index) { + const buttons = document.querySelectorAll('.opt'); + if (buttons[index]) { + buttons[index].click(); + } +} + +function showKeyboardHelp() { + const help = ` +⌨️ Atalhos de Teclado + +Quizzes: + 1-5 Selecionar opção A-E + SPC Próxima questão + ESC Fechar notas + +Geral: + ESC Fechar floaters + ? Mostrar esta ajuda + `; + + alert(help); +} + +document.addEventListener('keydown', (e) => { + // Ignorar se está digitando em um input/textarea + if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') { + return; + } + + const key = e.key; + const handler = SHORTCUTS[key]; + + if (handler) { + handler(e); + } +}); -- cgit v1.2.3