MCPcopy Create free account
hub / github.com/TanStack/hotkeys / App

Function App

examples/solid/createKeyHold/src/index.tsx:8–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

createKeyHoldFunction · 0.90

Tested by

no test coverage detected