示例工程 21-keyboard-focus-a11y

21-keyboard-focus-a11y/demo-01-shortcut-match/README.md

markdown · 0.9 KB

# demo-01-shortcut-match

把键盘事件规范化为 `meta+shift+k` 这样的字符串,再按作用域匹配命令。
同一组合在不同作用域可以是不同命令(对话框里的 Esc 与输入框里的 Esc)。

## 运行

```bash
pnpm --filter @tutorial/21-keyboard-focus-a11y-demo-01-shortcut-match start
```

## 验证

```bash
pnpm --filter @tutorial/21-keyboard-focus-a11y-demo-01-shortcut-match smoke
# {"evt":"smoke","ok":true,"normalized":["meta+shift+k",...],"matches":{...}}
```

## 说明

- 修饰键顺序固定为 meta → ctrl → alt → shift,避免同一组合出现两种写法。
- 匹配时 global 作用域始终参与,dialog / input 只在对应上下文生效。
- 单字母与 `/` 在输入框里应被忽略,匹配函数本身不判断,交给调用方。

## 已知限制

- 不处理键盘布局差异(`event.key` 已按布局给出字符)。
- 不处理长按重复(`event.repeat`)。