tanstack-hotkeys-guide
БесплатноБез исполняемых скриптовНе проверенTanStack Hotkeys guide for type-safe keyboard shortcuts in React. Use when user asks to "add keyboard shortcuts", "register hotkeys", "handle keyboard…
от vcode-sh★ 19 звёзд на GitHubОб этом скилле
Purpose
TanStack Hotkeys is a type-safe, framework-agnostic library for handling keyboard shortcuts. It provides React hooks for registering hotkeys, multi-key sequences, recording custom shortcuts, tracking key state, and platform-aware display formatting. The library uses event.key as its primary API with event.code fallback for letter/digit keys. Currently in alpha -- API may change.
When NOT to use: For a single shortcut listener, a plain addEventListener('keydown', ...) may suffice. Reach for TanStack Hotkeys when you need multiple shortcuts, cross-platform Mod handling, sequences, recording, or key-state tracking.
Instructions
- Always use
Modinstead of platform-specificMetaorControlfor cross-platform shortcuts - Import from
@tanstack/react-hotkeysfor React projects (it re-exports everything from@tanstack/hotkeys) - Import from
@tanstack/hotkeysonly for vanilla JS without React - Prefer the string form (
'Mod+S') over RawHotkey objects unless the hotkey is dynamic or built programmatically - Always add
tabIndex={0}to elements used astargetrefs -- they must be focusable to receive keyboard events - When building shortcut customization UIs, combine
useHotkeyRecorderwithformatForDisplayfor recording and display - The recorder auto-converts platform keys to portable
Modformat -- do not manually convert recorded hotkeys - Do NOT combine
ModwithControlorModwithMeta-- these create duplicate modifiers on one platform - Avoid
Alt+lettershortcuts for cross-platform apps -- macOS produces special characters with Option+letter - Avoid
Shift+numberandShift+punctuationshortcuts -- results are keyboard-layout-dependent - Warn the user that TanStack Hotkeys is in alpha when recommending it for production use
- Default
preventDefault: trueandstopPropagation: trueare intentional -- override explicitly only when needed - Use
conflictBehavior: 'allow'for intentional duplicate hotkeys, not to silence bugs
Installation
npm install @tanstack/react-hotkeys
The React package re-exports everything from @tanstack/hotkeys. No separate core install needed. For vanilla JS only, install @tanstack/hotkeys directly.
Optional devtools:
npm install @tanstack/react-devtools @tanstack/react-hotkeys-devtools
Quick Start
import { useHotkey } from '@tanstack/react-hotkeys'
function App() {
useHotkey('Mod+S', () => saveDocument())
return <div>Press Cmd+S (Mac) or Ctrl+S (Windows) to save</div>
}
Mod resolves to Meta (Cmd) on macOS and Control on Windows/Linux.
React Hooks Reference
useHotkey(hotkey, callback, options?)
Register a keyboard shortcut. Auto-syncs callback every render (no stale closures). Auto-unregisters on unmount.
useHotkey('Mod+S', (event, { hotkey, parsedHotkey }) => {
save()
})
Accept a string ('Mod+S') or RawHotkey object ({ key: 'S', mod: true }).
useHotkeySequence(sequence, callback, options?)
Register Vim-style multi-key sequences. Each step can include modifiers.
useHotkeySequence(['G', 'G'], () => scrollToTop())
useHotkeySequence(['Mod+K', 'Mod+C'], () => commentSelection())
Options: { timeout: 1000, enabled: true }.
useHotkeyRecorder(options)
Record custom keyboard shortcuts for settings UIs. Auto-converts to portable Mod format.
const { isRecording, recordedHotkey, startRecording, stopRecording, cancelRecording } =
useHotkeyRecorder({ onRecord: (hotkey) => setShortcut(hotkey) })
Options: { onRecord, onCancel?, onClear? }. Escape cancels. Backspace/Delete clears.
useHeldKeys()
Return a reactive string[] of currently held key names.
useHeldKeyCodes()
Return a reactive Record<string, string> mapping key names to event.code values.
useKeyHold(key)
Return boolean for a specific key's hold state. Only re-renders when that key changes.
const isShiftHeld = useKeyHold('Shift')
useDefaultHotkeysOptions()
Return the current default options from HotkeysProvider context.
useHotkeysContext()
Return the full hotkeys context value, or null if outside a provider.
HotkeysProvider
Wrap the app to set global default options. Per-hook options override provider defaults.
import { HotkeysProvider } from '@tanstack/react-hotkeys'
<HotkeysProvider defaultOptions={{
hotkey: { preventDefault: true },
hotkeySequence: { timeout: 1500 },
hotkeyRecorder: { onCancel: () => console.log('cancelled') },
}}>
<App />
</HotkeysProvider>
Hotkey String Format
- Modifiers:
Control,Alt,Shift,Meta - Cross-platform:
Mod(Cmd on Mac, Ctrl on Windows/Linux) - Format:
Modifier+Modifier+Key-- e.g.,'Mod+Shift+S' - Single keys:
'Escape','Enter','F1','ArrowUp','A','1','/' - RawHotkey alternative:
{ key: 'S', mod: true, shift: true } Mod+ControlandMod+Metacombinations are NOT allowed (would duplicate
Установить tanstack-hotkeys-guide в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл tanstack-hotkeys-guide?
TanStack Hotkeys guide for type-safe keyboard shortcuts in React. Use when user asks to "add keyboard shortcuts", "register hotkeys", "handle keyboard shortcuts in React", "implement key bindings", "use TanStack Hotkeys", "use useHotkey", "add Mod+S shortcut", "create vim-style key sequences", "record keyboard shortcuts", "track held keys", "format hotkey display", "show keyboard shortcut badges", or asks about "@tanstack/react-hotkeys", "useHotkey hook", "useHotkeySequence", "useHotkeyRecorder", "useHeldKeys", "useKeyHold", "HotkeyManager", "formatForDisplay", or "keyboard shortcut customization UI". Covers hotkey registration, multi-key sequences, hotkey recording, key state tracking, platform-aware display formatting, and devtools integration. Do NOT use for react-hotkeys-hook, Mousetrap, use-hotkeys, hotkeys-js, or other keyboard shortcut libraries -- this is specifically for @tanstack/react-hotkeys.
Как установить скилл tanstack-hotkeys-guide?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл tanstack-hotkeys-guide запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
frontend-design
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
от Anthropicwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
от Anthropicbrand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
от Anthropicweb-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…
от Anthropic