Skip to main content

Constructor

Creates a new HotKeyPad instance.
new HotKeyPad(options?: HotKeyPadOptionsProps)
options
HotKeyPadOptionsProps
Configuration options for the HotKeyPad instance. See Configuration for all available options.

Example

import HotKeyPad from 'hotkeypad';

const hotkeypad = new HotKeyPad({
  placeholder: 'Search commands...',
  activationLetter: 'K',
  closeKey: 'Escape',
  emptyMessage: 'No commands available'
});

Methods

setCommands()

Sets the commands to display in the command palette.
setCommands(commands: HotKeyPadCommand[]): void
commands
HotKeyPadCommand[]
required
Array of command objects. Each command must have an id, title, hotkey, and handler. See Types for the complete interface.

Example

hotkeypad.setCommands([
  {
    id: 'new-file',
    title: 'Create new file',
    icon: 'file',
    hotkey: 'Cmd+N',
    section: 'File',
    handler: (instance) => {
      console.log('Creating new file...');
    }
  },
  {
    id: 'save',
    title: 'Save file',
    icon: 'save',
    hotkey: 'Cmd+S',
    section: 'File',
    handler: (instance) => {
      console.log('Saving file...');
    }
  }
]);

open()

Opens the command palette interface.
open(): void
This method:
  • Makes the palette visible
  • Dispatches a hotkeypad:open custom event
  • Focuses the search input

Example

// Open programmatically
hotkeypad.open();

// Listen for open events
window.addEventListener('hotkeypad:open', () => {
  console.log('Command palette opened');
});

close()

Closes the command palette interface.
close(): void
This method:
  • Hides the palette
  • Dispatches a hotkeypad:close custom event
  • Clears the search input
  • Removes event listeners

Example

// Close programmatically
hotkeypad.close();

// Listen for close events
window.addEventListener('hotkeypad:close', () => {
  console.log('Command palette closed');
});

Properties

activationKey

Returns the activation key based on the user’s operating system.
get activationKey(): string
activationKey
string
Returns "Cmd" on macOS or "Ctrl" on other platforms. This is automatically detected based on the user agent.

Example

const key = hotkeypad.activationKey;
console.log(key); // "Cmd" on macOS, "Ctrl" on Windows/Linux

// Use it in your UI
const shortcut = `${hotkeypad.activationKey}+K`;

instance

Reference to the root HTML element with id hotkeypad.
instance: HTMLElement
instance
HTMLElement
The DOM element that serves as the container for the entire HotKeyPad interface.

Build docs developers (and LLMs) love