Skip to content
Discussion options

You must be logged in to vote

To add a keyboard shortcut (e.g., Ctrl+S) for the Settings app:
1. Open src/components/Desktop.js.
2. Add an event listener for keydown events using useEffect:
javascript<br>import { useEffect } from 'react';<br>import { useAppContext } from '@/context/AppContext';<br>const Desktop = () => {<br> const { openApp } = useAppContext();<br> useEffect(() => {<br> const handleKeydown = (e) => {<br> if (e.ctrlKey && e.key === 's') openApp('settings');<br> };<br> window.addEventListener('keydown', handleKeydown);<br> return () => window.removeEventListener('keydown', handleKeydown);<br> }, [openApp]);<br> // ... rest of component<br>};<br>
3. Test with npm run dev by pressing Ctrl+S.
4. Update tests in t…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dailker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
help wanted Extra attention is needed question Further information is requested
2 participants