Agent Skills › lobehub/lobehub › hotkey

hotkey

GitHub

提供前端键盘快捷键的添加指南,涵盖常量定义、注册、国际化及Hook使用,帮助开发者规范实现快捷键功能。

.agents/skills/hotkey/SKILL.md lobehub/lobehub

Trigger Scenarios

需要添加新的键盘快捷键 配置快捷键的注册与绑定 解决快捷键冲突或作用域问题

Install

npx skills add lobehub/lobehub --skill hotkey -g -y
More Options

Non-standard path

npx skills add https://github.com/lobehub/lobehub/tree/canary/.agents/skills/hotkey -g -y

Use without installing

npx skills use lobehub/lobehub@hotkey

指定 Agent (Claude Code)

npx skills add lobehub/lobehub --skill hotkey -a claude-code -g -y

安装 repo 全部 skill

npx skills add lobehub/lobehub --all -g -y

预览 repo 内 skill

npx skills add lobehub/lobehub --list

SKILL.md

Frontmatter
{
    "name": "hotkey",
    "description": "Use for keyboard shortcuts, registration, key combinations, scope, conflicts and shortcut tooltips.",
    "user-invocable": false
}

Adding Keyboard Shortcuts Guide

Steps to Add a New Hotkey

1. Update Hotkey Constant

In packages/types/src/hotkey.ts, add the new id to the HotkeyId union — it's the source of truth HotkeyEnum is typed against:

export type HotkeyId =
  | 'addUserMessage'
  // existing...
  | 'saveTopic';

2. Register Default Hotkey

In packages/const/src/hotkeys.ts, KeyEnum and combineKeys are already defined locally in this file, so no import is needed — add the entry to HotkeyEnum and to HOTKEYS_REGISTRATION:

export const HotkeyEnum = {
  // existing...
  SaveTopic: 'saveTopic',
} as const satisfies Record<string, HotkeyId>;

export const HOTKEYS_REGISTRATION: HotkeyRegistration = [
  // existing...
  {
    group: HotkeyGroupEnum.Conversation,
    id: HotkeyEnum.SaveTopic,
    keys: combineKeys([KeyEnum.Alt, 'n']),
    scopes: [HotkeyScopeEnum.Chat],
  },
];

3. Add i18n Translation

In packages/locales/src/default/hotkey.ts:

const hotkey: HotkeyI18nTranslations = {
  saveTopic: {
    desc: '保存当前话题并新建一个话题',
    title: '保存话题',
  },
};

4. Create and Register Hook

In src/hooks/useHotkeys/chatScope.ts:

export const useSaveTopicHotkey = () => {
  const openNewTopicOrSaveTopic = useChatStore((s) => s.openNewTopicOrSaveTopic);
  return useHotkeyById(HotkeyEnum.SaveTopic, openNewTopicOrSaveTopic);
};

export const useRegisterChatHotkeys = () => {
  useSaveTopicHotkey();
  // ...other hotkeys
};

5. Add Tooltip (Optional)

const saveTopicHotkey = useUserStore(settingsSelectors.getHotkeyById(HotkeyEnum.SaveTopic));

<Tooltip hotkey={saveTopicHotkey} title={t('saveTopic.title', { ns: 'hotkey' })}>
  <Button icon={<SaveOutlined />} onClick={openNewTopicOrSaveTopic} />
</Tooltip>;

Best Practices

  1. Scope: Choose global or chat scope based on functionality
  2. Grouping: Place in appropriate group (System/Layout/Conversation)
  3. Conflict check: Ensure no conflict with system/browser shortcuts
  4. Platform: Use KeyEnum.Mod instead of hardcoded Ctrl or Cmd
  5. Clear description: Provide title and description for users

Troubleshooting

  • Not working: Check scope and RegisterHotkeys hook
  • Not in settings: Verify HOTKEYS_REGISTRATION config
  • Conflict: HotkeyInput component shows warnings
  • Page-specific: Ensure correct scope activation

Version History

  • 69012b8 Current 2026-09-28 20:13

    重构了快捷键类型系统,从枚举对象改为TypeScript联合类型以增强类型安全;优化了模块路径和导入方式。

  • e0d4b61 2026-09-23 09:52
  • 29fe043 2026-08-20 18:33

Same Skill Collection

.agents/skills/add-model-provider/SKILL.md
.agents/skills/add-provider-doc/SKILL.md
.agents/skills/add-setting-env/SKILL.md
.agents/skills/agent-runtime-hooks/SKILL.md
.agents/skills/agent-signal/SKILL.md
.agents/skills/agent-testing-bot/SKILL.md
.agents/skills/agent-tracing/SKILL.md
.agents/skills/agent-work/SKILL.md
.agents/skills/alint-ruleset/SKILL.md
.agents/skills/builtin-tool/SKILL.md
.agents/skills/chat-sdk/SKILL.md
.agents/skills/cleanup-git-worktrees/SKILL.md
.agents/skills/cli/SKILL.md
.agents/skills/compose-atoms/SKILL.md
.agents/skills/data-fetching-architecture/SKILL.md
.agents/skills/db-migrations/SKILL.md
.agents/skills/debug-frontend-with-browser/SKILL.md
.agents/skills/debug-package/SKILL.md
.agents/skills/deep-review/SKILL.md
.agents/skills/design-prototype/SKILL.md
.agents/skills/desktop-security-update/SKILL.md
.agents/skills/desktop/SKILL.md
.agents/skills/docs-changelog/SKILL.md
.agents/skills/drizzle/SKILL.md
.agents/skills/full-text-search/SKILL.md
.agents/skills/heterogeneous-agent/SKILL.md
.agents/skills/i18n/SKILL.md
.agents/skills/linear/SKILL.md
.agents/skills/llm-generation/SKILL.md
.agents/skills/modal/SKILL.md
.agents/skills/model-bank-metadata/SKILL.md
.agents/skills/product-design/SKILL.md
.agents/skills/project-overview/SKILL.md
.agents/skills/react/SKILL.md
.agents/skills/response-compliance/SKILL.md
.agents/skills/run-eval-harbor/SKILL.md
.agents/skills/skills-audit/SKILL.md
.agents/skills/source-layout/SKILL.md
.agents/skills/spa-routes/SKILL.md
.agents/skills/split-large-file/SKILL.md
.agents/skills/split-micro-app/SKILL.md
.agents/skills/store-data-structures/SKILL.md
.agents/skills/testing-heterogeneous-agents/SKILL.md
.agents/skills/testing/SKILL.md
.agents/skills/trpc-router/SKILL.md
.agents/skills/typescript/SKILL.md
.agents/skills/upstash-workflow/SKILL.md
.agents/skills/ux-audit/SKILL.md
.agents/skills/ux/SKILL.md

Metadata

Files
0
Version
aace12f
Hash
fbcec283
Indexed
2026-08-20 18:33

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-10-24 15:04
浙ICP备14020137号-1