1.0.2 • Published 8 months ago

@rsxt/react-keyboard-shortcuts v1.0.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

@rsxt/react-keyboard-shortcuts

šŸš€ @rsxt/react-keyboard-shortcuts is a powerful and flexible React hook for handling keyboard shortcuts, supporting:

āœ… Single and Multi-Key Shortcuts ("Ctrl+S", "Shift+D", etc.) āœ… Ordered & Unordered Key Combinations āœ… Multi-Key Sequences ("Ctrl+K Ctrl+D") āœ… Debug Mode for Logging Key Events āœ… Supports Both ESM & CommonJS


šŸ“¦ Installation

yarn add @rsxt/react-keyboard-shortcuts

OR

npm install @rsxt/react-keyboard-shortcuts

šŸš€ Usage

1ļøāƒ£ Basic Keyboard Shortcut

import { useKeyboardShortcut } from "@rsxt/react-keyboard-shortcuts";

useKeyboardShortcut("a", () => {
  console.log("Key 'A' pressed!");
});

2ļøāƒ£ Key Combination (Ctrl+S)

useKeyboardShortcut("Ctrl+S", () => {
  console.log("Save triggered!");
});

3ļøāƒ£ Ordered Key Combination (Ctrl+A+S)

useKeyboardShortcut(
  ["Ctrl", "A", "S"],
  () => {
    console.log("Triggered only in order Ctrl → A → S");
  },
  { ordered: true }
);

4ļøāƒ£ Multi-Key Sequence (Ctrl+K Ctrl+D)

useKeyboardShortcut("Ctrl+K Ctrl+D", () => {
  console.log("Triggered after `Ctrl+K`, then `Ctrl+D`");
});

5ļøāƒ£ Enable Debug Mode

useKeyboardShortcut(
  "Ctrl+S",
  () => {
    console.log("Save triggered!");
  },
  { debug: true }
);

šŸ“Œ Console Output (When Debug is Enabled):

šŸž  [12:30:15 PM] Key Pressed { key: "Ctrl+S" }
āœ…  [12:30:16 PM] Shortcut Triggered { shortcut: "Ctrl+S" }

šŸ“Œ Options

OptionTypeDefaultDescription
preventDefaultbooleantruePrevents the default browser action on shortcut press.
enabledbooleantrueEnables or disables the keyboard shortcut.
orderedbooleanfalseEnsures keys must be pressed in sequence when set to true.
debugbooleanfalseLogs key events for debugging.

šŸ›  Contributing

Pull requests and feature suggestions are welcome! Open an issue if you encounter any problems.


šŸ“„ License

MIT License Ā© 2025 @rsxt

1.0.2

8 months ago

1.0.1

8 months ago