Skip to content

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

参数

参数名类型必填说明
userAgentstring浏览器 UA;getShortcutModKeyHint 缺省或空串时返回 Ctrl 方案

返回值

函数类型说明
prefersMetaModifierInShortcutUibooleanmacOS / iOS 为 true
getShortcutModKeyHintShortcutModKeyHintmodKeyLabelCtrl)、ariaKeyshortcutstitle

macOS/iOS 返回 { modKeyLabel: '⌘', ariaKeyshortcuts: 'Meta+K', title: '快捷键 Command K' };其它平台返回 Control 方案。

工作原理

  1. prefersMetaModifierInShortcutUi 内部调用 detectOS({ userAgent }),判断是否为 macOSiOS
  2. getShortcutModKeyHint 按上述结果选择预置 META 或 CTRL 常量对象。
  3. 纯函数,无环境注入;调用方传入 UA 即可。

异常

无异常抛出。