Skip to content

feat: add useKeyPress, useKeyCombination, and useKeySequence hooks#713

Open
PeterPCW wants to merge 1 commit intojuliencrn:masterfrom
PeterPCW:feature/keyboard-hooks
Open

feat: add useKeyPress, useKeyCombination, and useKeySequence hooks#713
PeterPCW wants to merge 1 commit intojuliencrn:masterfrom
PeterPCW:feature/keyboard-hooks

Conversation

@PeterPCW
Copy link

@PeterPCW PeterPCW commented Feb 1, 2026

Summary

This PR adds three new keyboard interaction hooks to the library.

New Hooks

  1. useKeyPress(targetKey, options?)
  • Tracks whether a specific key is currently pressed
  • Supports single key monitoring with configurable event types
  • Useful for keyboard shortcuts, game controls, or modal dismissals
  1. useKeyCombination(combo, handler, options?)
  • Detects when multiple keys are pressed simultaneously
  • Triggers callback when all keys in the combo are pressed
  • Perfect for shortcuts like Ctrl+S, Cmd+K, or Ctrl+Shift+E
  1. useKeySequence(handler, sequence, options?)
  • Detects when a specific sequence of keys is typed in order
  • Supports "cheat codes" like Konami code (↑↑↓↓←→←→BA)
  • Configurable timeout resets sequence if typing slows

Example Usage

// Single key press
const isPressed = useKeyPress('Escape')
// Key combination
useKeyCombination(['Control', 's'], () => saveDocument())
// Key sequence
useKeySequence('hello', () => showSecretMessage())

Testing

  • All hooks include comprehensive unit tests covering:
  • Basic functionality
  • Event target handling (including null)
  • Case-insensitive key matching
  • Timeout behavior (for sequences)
  • Edge cases

@changeset-bot
Copy link

changeset-bot bot commented Feb 1, 2026

⚠️ No Changeset found

Latest commit: fb542be

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant