Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Sebas200702/AniDev/llms.txt
Use this file to discover all available pages before exploring further.
useShortcuts
TheuseShortcuts hook manages keyboard shortcuts throughout your application, supporting complex key combinations including modifier keys (Ctrl, Shift, Alt) and providing a clean API for mapping shortcuts to actions.
Type Signature
Parameters
Array of shortcut definitions, each containing:
keys: Array of key names (e.g.,['ctrl', 's'])action: String identifier for the action to trigger
Object mapping action identifiers to callback functions that execute when shortcuts are triggered
Return Value
This hook doesn’t return any value. It sets up global keyboard event listeners that trigger the mapped actions.Usage Examples
Basic Save Shortcut
Multiple Shortcuts
Navigation Shortcuts
Complex Modifier Combinations
Search Shortcut
Modal Control
Supported Keys
Modifier Keys
ctrl- Control key (Cmd on Mac)shift- Shift keyalt- Alt key (Option on Mac)
Special Keys
escape- Escape keyenter- Enter/Return keyspace- Spacebararrowup,arrowdown,arrowleft,arrowright- Arrow keystab- Tab keybackspace- Backspace keydelete- Delete key
Character Keys
- Any letter:
a,b,c, etc. (automatically lowercased) - Numbers:
0,1,2, etc. - Function keys:
f1,f2,f3, etc.
All key names are automatically converted to lowercase for consistent matching. Use lowercase in your shortcut definitions.
Use Cases
- Video player controls - Play/pause, volume, fullscreen
- Image galleries - Navigation, zoom, close
- Text editors - Save, undo/redo, formatting
- Search interfaces - Focus search, clear input
- Modal dialogs - Close with Escape
- Application navigation - Quick access to different sections
- Accessibility - Keyboard-only navigation support
How It Works
- Event Registration: The hook sets up a global
keydownevent listener onwindow - Key Combination: When a key is pressed, it builds a combination string like
ctrl+s - Action Lookup: It looks up the combination in the shortcuts map
- Prevention: If a match is found, it prevents the default browser behavior
- Execution: It executes the corresponding action from the action map
- Cleanup: Event listeners are removed when the component unmounts
Best Practices
Document Your Shortcuts
Conditional Shortcuts
Avoid Conflicts
Be careful not to override critical browser shortcuts:
Ctrl+T(new tab)Ctrl+W(close tab)Ctrl+N(new window)Ctrl+Tab(switch tabs)
Accessibility Considerations
- Always provide visible indicators for keyboard shortcuts
- Ensure shortcuts don’t conflict with screen reader commands
- Test with keyboard-only navigation
- Document all shortcuts in your help documentation
- Consider providing customizable shortcuts for power users
Source
Location:src/domains/shared/hooks/useShortCuts.ts:6