@gentleduck/shortcut
v0.1.0
Published
[DEPRECATED: use @gentleduck/vim instead] A lightweight React component for easily binding and handling keyboard shortcuts in your React applications.
Maintainers
Readme
@gentleduck/shortcut
Deprecated -- use
@gentleduck/viminstead.
Keyboard shortcut hook for React.
Quick start
npm install @gentleduck/shortcutimport { useDuckShortcut } from '@gentleduck/shortcut'
function App() {
useDuckShortcut({
keys: ['ctrl+s'],
onKeysPressed: () => console.log('Ctrl+S pressed'),
})
return <div>Press Ctrl+S</div>
}Features
- Key combinations (
ctrl+s,command+k) - Key sequences (
Up Up Down Down Left Right B A Enter) - Mixed combinations and sequences in one binding
- Global listener -- no event capture conflicts
- Case-insensitive key names
- Multiple instances without conflicts
API
useDuckShortcut
interface DuckShortcutProps {
keys: string | string[]
onKeysPressed: () => void
}
declare function useDuckShortcut(props: DuckShortcutProps): void| Prop | Type | Description |
| --- | --- | --- |
| keys | string \| string[] | Shortcut bindings -- combinations ('ctrl+s') or sequences ('Up Up Down Down') |
| onKeysPressed | () => void | Called when any listed shortcut fires |
