shortcutModKeyHint
根据 User-Agent 返回快捷键 UI 的主修饰键展示文案(⌘ 或 Ctrl)。
函数签名
typescript
interface ShortcutModKeyHint {
modKeyLabel: string
ariaKeyshortcuts: string
title: string
}
function prefersMetaModifierInShortcutUi(userAgent: string): boolean
function getShortcutModKeyHint(userAgent: string | undefined): ShortcutModKeyHint参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
userAgent | string | 是 | 浏览器 UA;getShortcutModKeyHint 缺省或空串时返回 Ctrl 方案 |
返回值
| 函数 | 类型 | 说明 |
|---|---|---|
prefersMetaModifierInShortcutUi | boolean | macOS / iOS 为 true |
getShortcutModKeyHint | ShortcutModKeyHint | 含 modKeyLabel(⌘ 或 Ctrl)、ariaKeyshortcuts、title |
macOS/iOS 返回 { modKeyLabel: '⌘', ariaKeyshortcuts: 'Meta+K', title: '快捷键 Command K' };其它平台返回 Control 方案。
工作原理
prefersMetaModifierInShortcutUi内部调用detectOS({ userAgent }),判断是否为macOS或iOS。getShortcutModKeyHint按上述结果选择预置 META 或 CTRL 常量对象。- 纯函数,无环境注入;调用方传入 UA 即可。
异常
无异常抛出。