summaryrefslogtreecommitdiff
path: root/static/keyboard-shortcuts.js
blob: 53cfe449fcfa282442a5887e428cab6a6dacd3bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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);
  }
});