Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Keyboard Shortcuts

ABCrimson edited this page Mar 11, 2026 · 2 revisions

Keyboard Shortcuts

Shortcut Syntax

Shortcuts use a modifier+key string format:

Syntax Meaning
Mod+K Cmd+K on macOS, Ctrl+K on Windows/Linux
Ctrl+Shift+P Ctrl+Shift+P on all platforms
Alt+N Alt+N / Option+N
Mod+Shift+Enter Cmd+Shift+Enter / Ctrl+Shift+Enter

Mod is the platform-aware modifier — it resolves to Meta (Cmd) on macOS and Control on other platforms.

Using Shortcuts in React

<Command.Item value="new-file" shortcut="Mod+N" onSelect={() => createFile()}>
 <span>New File</span>
 <Command.Shortcut shortcut="Mod+N" />
</Command.Item>

Parser API

import { parseShortcut, formatShortcut } from 'modern-cmdk';
const parsed = parseShortcut('Mod+Shift+P');
// { meta: true, ctrl: false, shift: true, alt: false, key: 'p' }
// (meta is true on macOS, ctrl on Windows)
const display = formatShortcut(parsed);
// "⌘⇧P" on macOS, "Ctrl+Shift+P" on Windows

Conflict Detection

import { detectConflicts } from 'modern-cmdk';
const shortcuts = [
 { id: 'copy', shortcut: 'Mod+C' },
 { id: 'custom-copy', shortcut: 'Mod+C' }, // Conflict!
 { id: 'paste', shortcut: 'Mod+V' },
];
const conflicts = detectConflicts(shortcuts);
// Map { "mod+c" => ["copy", "custom-copy"] }

Uses Object.groupBy (ES2026) internally for efficient conflict grouping.

Parser Internals

The parser uses RegExp.escape (ES2026) for safe pattern construction when processing shortcut strings, preventing injection of special regex characters.

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /