()
| 12 | import './index.css' |
| 13 | |
| 14 | function App() { |
| 15 | const heldKeys = createHeldKeys() |
| 16 | const heldCodes = createHeldKeyCodes() |
| 17 | const [history, setHistory] = createSignal<Array<string>>([]) |
| 18 | |
| 19 | createEffect(() => { |
| 20 | const keys = heldKeys() |
| 21 | if (keys.length > 0) { |
| 22 | const combo = keys |
| 23 | .map((k) => formatForDisplay(k, { useSymbols: true })) |
| 24 | .join(' + ') |
| 25 | setHistory((h) => { |
| 26 | if (h[h.length - 1] !== combo) { |
| 27 | return [...h.slice(-9), combo] |
| 28 | } |
| 29 | return h |
| 30 | }) |
| 31 | } |
| 32 | }) |
| 33 | |
| 34 | return ( |
| 35 | <div class="app"> |
| 36 | <header> |
| 37 | <h1>createHeldKeys</h1> |
| 38 | <p> |
| 39 | Returns a signal of all currently pressed keys. Useful for displaying |
| 40 | key combinations or building custom shortcut recording. |
| 41 | </p> |
| 42 | </header> |
| 43 | |
| 44 | <main> |
| 45 | <section class="demo-section"> |
| 46 | <h2>Currently Held Keys</h2> |
| 47 | <div class="key-display"> |
| 48 | {heldKeys().length > 0 ? ( |
| 49 | heldKeys().map((key, index) => { |
| 50 | const code = heldCodes()[key] |
| 51 | return ( |
| 52 | <> |
| 53 | {index > 0 && <span class="plus">+</span>} |
| 54 | <kbd class="large"> |
| 55 | {formatForDisplay(key, { useSymbols: true })} |
| 56 | {code && code !== key && ( |
| 57 | <small class="code-label">{code}</small> |
| 58 | )} |
| 59 | </kbd> |
| 60 | </> |
| 61 | ) |
| 62 | }) |
| 63 | ) : ( |
| 64 | <span class="placeholder">Press any keys...</span> |
| 65 | )} |
| 66 | </div> |
| 67 | <div class="stats"> |
| 68 | Keys held: <strong>{heldKeys().length}</strong> |
| 69 | </div> |
| 70 | </section> |
| 71 |
nothing calls this directly
no test coverage detected