The keyboard event
Key combination string (e.g., 'ctrl+shift+k')
// In event handler
document.addEventListener('keydown', (event) => {
const combo = getKeyCombination(event);
// Match against shortcuts
if (combo === 'ctrl+shift+k' || combo === 'cmd+shift+k') {
event.preventDefault();
openCommandPalette();
}
// Log for debugging
console.log('Key combo:', combo);
// Examples: 'ctrl+s', 'cmd+k', 'shift+enter', 'escape'
});
// Handle special keys
// Space key: 'ctrl+space'
// Escape key: 'escape'
// Enter key: 'shift+enter'
Get key combination string from keyboard event
Converts KeyboardEvent to a normalized key combination string. Handles platform differences (Cmd vs. Ctrl) and special keys.