2025-08-17 16:27:02 +02:00
2025-08-16 17:11:22 +02:00
2025-08-16 17:11:22 +02:00
2025-08-16 17:11:22 +02:00
2025-08-17 16:27:02 +02:00
2025-08-17 16:27:02 +02:00
2025-08-16 17:11:22 +02:00

hyperf-keybinds

Quickly handle keyboard shortcuts and sequences in your app.

Install

npm install hyperf-keybinds

Quick Start

import { createKeyHandler, KeybindEventTypes, ModifierKey } from 'hyperf-keybinds';

// Define a command
const commands = [
  { command: [{ key: 'KeyS', modifiers: [ModifierKey.Control] }], callback: () => console.log('Ctrl+S!') },
  { command: [{ key: 'KeyA', modifiers: []}, { key: 'KeyS', modifiers: []}], callback: () => console.log('a - s!')}
];

// Create handler and emitter
const { handler, emitter } = createKeyHandler(commands);

// Attach to window
window.addEventListener('keydown', handler);

// Listen to events
emitter.on(e => console.log(e.type));

Now Ctrl+S triggers your callback and emits events. Pressing a then s triggers a separate callback.

Description
Supporting multiple keypresses mapping to callbacks
Readme 54 KiB
Languages
TypeScript 100%