PluginBench
Skill
Review
Audit score 70

hotkey

lobehub/lobehub

Add or edit LobeHub keyboard shortcuts with proper registration and i18n support.

What is hotkey?

This skill enables you to create and manage keyboard shortcuts in LobeHub by defining hotkey constants, registering default key combinations, adding translations, and hooking them into UI components. Use it when you need to add new keyboard shortcuts or modify existing ones across the application.

  • Define new hotkeys in HotkeyEnum with unique identifiers
  • Register default key combinations using combineKeys and scope configuration
  • Add internationalized titles and descriptions for hotkeys
  • Create and register hooks that bind hotkeys to actions using useHotkeyById
  • Add hotkey tooltips to UI buttons and components
  • Handle platform-specific key combinations (Cmd/Ctrl) with Key.Mod

How to install hotkey

npx skills add https://github.com/lobehub/lobehub --skill hotkey
Prerequisites
  • Access to LobeHub source code repository
  • Familiarity with TypeScript and React hooks
  • Understanding of LobeHub's file structure (src/types, src/const, src/locales, src/hooks)
Claude Code
Cursor
Windsurf
Cline

How to use hotkey

  1. 1.Update HotkeyEnum in src/types/hotkey.ts with a new hotkey identifier
  2. 2.Register the hotkey in HOTKEYS_REGISTRATION in src/const/hotkeys.ts with key combination and scope
  3. 3.Add i18n translations in src/locales/default/hotkey.ts with title and description
  4. 4.Create a custom hook in src/hooks/useHotkeys/ that uses useHotkeyById to bind the hotkey to an action
  5. 5.Register the hook in the appropriate scope hook (e.g., useRegisterChatHotkeys)
  6. 6.Optionally add a Tooltip component to UI elements to display the hotkey to users

Use cases

Good for
  • Adding a new keyboard shortcut for clearing chat history (Cmd/Ctrl+Shift+Backspace)
  • Creating chat-scoped hotkeys that only work in conversation context
  • Implementing global hotkeys for system-wide actions
  • Adding hotkey tooltips to buttons so users discover keyboard shortcuts
  • Preventing hotkey conflicts with system and browser shortcuts
Who it's for
  • LobeHub developers adding new features
  • Contributors implementing keyboard navigation
  • Developers customizing hotkey behavior for specific scopes
  • Teams managing multi-language hotkey documentation

hotkey FAQ

What is the difference between global and chat scope hotkeys?

Global scope hotkeys work anywhere in the application, while chat scope hotkeys only activate when in the conversation/chat context. Choose based on where the action should be available.

Why should I use Key.Mod instead of hardcoding Ctrl or Cmd?

Key.Mod automatically resolves to Cmd on macOS and Ctrl on Windows/Linux, ensuring cross-platform compatibility without platform-specific code.

How do I check for hotkey conflicts?

The HotkeyInput component shows warnings for conflicts. Verify your chosen combination doesn't conflict with system shortcuts (like Cmd+Q on macOS) or browser shortcuts.

What if my hotkey isn't appearing in settings?

Ensure the hotkey is added to HOTKEYS_REGISTRATION in src/const/hotkeys.ts and that the hook is properly registered in the appropriate scope hook.

Can I have different hotkeys for different languages?

The hotkey key combination is the same across languages, but the title and description are translated via i18n in src/locales/default/hotkey.ts.

Full instructions (SKILL.md)

Source of truth, from lobehub/lobehub.


name: hotkey description: 'Add or edit LobeHub keyboard shortcuts. Use for HotkeyEnum, HOTKEYS_REGISTRATION, combineKeys, useHotkeyById, tooltip hotkeys, shortcut scope, conflicts, or Cmd/Ctrl key combos.' user-invocable: false

Adding Keyboard Shortcuts Guide

Steps to Add a New Hotkey

1. Update Hotkey Constant

In src/types/hotkey.ts:

export const HotkeyEnum = {
  // existing...
  ClearChat: 'clearChat', // Add new
} as const;

2. Register Default Hotkey

In src/const/hotkeys.ts:

import { KeyMapEnum as Key, combineKeys } from '@lobehub/ui';

export const HOTKEYS_REGISTRATION: HotkeyRegistration = [
  {
    group: HotkeyGroupEnum.Conversation,
    id: HotkeyEnum.ClearChat,
    keys: combineKeys([Key.Mod, Key.Shift, Key.Backspace]),
    scopes: [HotkeyScopeEnum.Chat],
  },
];

3. Add i18n Translation

In src/locales/default/hotkey.ts:

const hotkey: HotkeyI18nTranslations = {
  clearChat: {
    desc: '清空当前会话的所有消息记录',
    title: '清空聊天记录',
  },
};

4. Create and Register Hook

In src/hooks/useHotkeys/chatScope.ts:

export const useClearChatHotkey = () => {
  const clearMessages = useChatStore((s) => s.clearMessages);
  return useHotkeyById(HotkeyEnum.ClearChat, clearMessages);
};

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

5. Add Tooltip (Optional)

const clearChatHotkey = useUserStore(settingsSelectors.getHotkeyById(HotkeyEnum.ClearChat));

<Tooltip hotkey={clearChatHotkey} title={t('clearChat.title', { ns: 'hotkey' })}>
  <Button icon={<DeleteOutlined />} onClick={clearMessages} />
</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 Key.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