本页还没有译文
本页 17 段还没译成Français,下面显示的是英文原文。Hotkey
还没翻译译自英文(tanstack.com)本页 17 段都还没译
type Hotkey =
| Key
| SingleModifierHotkey
| TwoModifierHotkey
| ThreeModifierHotkey
| FourModifierHotkey;Defined in: hotkey.types.ts:126
A type-safe hotkey string.
Provides autocomplete for:
- All single keys (letters, numbers, function keys, navigation, editing, punctuation)
- Single modifier + common key (Control+S, Mod+A, Mod+/, etc.)
- Two modifiers + common key (Mod+Shift+S, Control+Alt+A, etc.)
- Three modifiers + common key (Control+Alt+Shift+A, Mod+Alt+Shift+S, etc.)
- Four modifiers + common key (Control+Alt+Shift+Meta+A, etc.)
Modifier Names
Use canonical modifier names:
Control(not Ctrl) - The Control keyAlt(not Option) - The Alt key (Option on macOS)Meta(not Command/Cmd) - The Meta/Command key (macOS only)Shift- The Shift key
Platform-Adaptive Mod Modifier
The Mod modifier is a special platform-adaptive modifier that automatically resolves
to the "primary modifier" on each platform:
- macOS:
Mod→Meta(Command key ⌘) - Windows/Linux:
Mod→Control(Ctrl key)
This enables cross-platform hotkey definitions that work correctly on all platforms
without platform-specific code. The Mod modifier is resolved at runtime based on
the detected platform.
When to use Mod vs platform-specific modifiers:
- Use
Modfor cross-platform shortcuts (e.g.,Mod+Sfor save) - Use
MetaorControlwhen you need platform-specific behavior - Use
Modwhen you want your shortcuts to follow platform conventions automatically
Limitations:
Mod+ControlandMod+Metacombinations are not allowed (they create duplicate modifiers on one platform)- In four-modifier combinations, only canonical modifiers are allowed (no
Mod)
Example
// Cross-platform shortcuts (recommended)
const save: Hotkey = 'Mod+S' // Command+S on Mac, Ctrl+S on Windows/Linux
const saveAs: Hotkey = 'Mod+Shift+S' // Command+Shift+S on Mac, Ctrl+Shift+S elsewhere
const comment: Hotkey = 'Mod+/' // Command+/ on Mac, Ctrl+/ elsewhere
// Platform-specific shortcuts
const macOnly: Hotkey = 'Meta+S' // Command+S on Mac only
const windowsOnly: Hotkey = 'Control+S' // Ctrl+S on Windows/Linux onlyAI 翻译查看英文原文