()
| 5 | import './index.css' |
| 6 | |
| 7 | function App() { |
| 8 | // const isModHeld = useKeyHold('') |
| 9 | const isShiftHeld = useKeyHold('Shift') |
| 10 | const isControlHeld = useKeyHold('Control') |
| 11 | const isAltHeld = useKeyHold('Alt') |
| 12 | const isMetaHeld = useKeyHold('Meta') |
| 13 | const isSpaceHeld = useKeyHold('Space') |
| 14 | |
| 15 | return ( |
| 16 | <div className="app"> |
| 17 | <header> |
| 18 | <h1>useKeyHold</h1> |
| 19 | <p> |
| 20 | Returns a boolean indicating if a specific key is currently held. |
| 21 | Optimized to only re-render when that specific key changes. |
| 22 | </p> |
| 23 | </header> |
| 24 | |
| 25 | <main> |
| 26 | <section className="demo-section"> |
| 27 | <h2>Modifier Key States</h2> |
| 28 | <div className="modifier-grid"> |
| 29 | <div |
| 30 | className={`modifier-indicator ${isShiftHeld ? 'active' : ''}`} |
| 31 | > |
| 32 | <span className="key-name">Shift</span> |
| 33 | <span className="status"> |
| 34 | {isShiftHeld ? 'HELD' : 'Released'} |
| 35 | </span> |
| 36 | </div> |
| 37 | <div |
| 38 | className={`modifier-indicator ${isControlHeld ? 'active' : ''}`} |
| 39 | > |
| 40 | <span className="key-name">Control</span> |
| 41 | <span className="status"> |
| 42 | {isControlHeld ? 'HELD' : 'Released'} |
| 43 | </span> |
| 44 | </div> |
| 45 | <div className={`modifier-indicator ${isAltHeld ? 'active' : ''}`}> |
| 46 | <span className="key-name">Alt / Option</span> |
| 47 | <span className="status">{isAltHeld ? 'HELD' : 'Released'}</span> |
| 48 | </div> |
| 49 | <div className={`modifier-indicator ${isMetaHeld ? 'active' : ''}`}> |
| 50 | <span className="key-name">Meta (⌘ / ⊞)</span> |
| 51 | <span className="status">{isMetaHeld ? 'HELD' : 'Released'}</span> |
| 52 | </div> |
| 53 | </div> |
| 54 | </section> |
| 55 | |
| 56 | <section className="demo-section"> |
| 57 | <h2>Space Bar Demo</h2> |
| 58 | <div className={`space-indicator ${isSpaceHeld ? 'active' : ''}`}> |
| 59 | {isSpaceHeld ? '🚀 SPACE HELD!' : 'Hold Space Bar'} |
| 60 | </div> |
| 61 | </section> |
| 62 | |
| 63 | <section className="demo-section"> |
| 64 | <h2>Usage</h2> |
nothing calls this directly
no test coverage detected