| 196 | } |
| 197 | |
| 198 | render() { |
| 199 | return html` <div class="app"> |
| 200 | <header> |
| 201 | <h1>@hotkey</h1> |
| 202 | <p> |
| 203 | Register keyboard shortcuts with callback context containing the |
| 204 | hotkey and parsed hotkey information. |
| 205 | </p> |
| 206 | </header> |
| 207 | |
| 208 | <main> |
| 209 | <section class="demo-section"> |
| 210 | <h2>Basic Hotkey</h2> |
| 211 | <p>Press <kbd>${formatForDisplay('Mod+S')}</kbd> to trigger</p> |
| 212 | <div class="counter">Save triggered: ${this.saveCount}x</div> |
| 213 | <pre class="code-block"> |
| 214 | ${`@hotkey('Mod+S', (_event, { hotkey, parsedHotkey }) => { |
| 215 | console.log('Hotkey:', hotkey) |
| 216 | console.log('Parsed:', parsedHotkey) |
| 217 | })`}</pre |
| 218 | > |
| 219 | </section> |
| 220 | |
| 221 | <section class="demo-section"> |
| 222 | <h2>With requireReset</h2> |
| 223 | <p> |
| 224 | Hold <kbd>${formatForDisplay('Mod+K')}</kbd> — only increments once |
| 225 | until you release all keys |
| 226 | </p> |
| 227 | <div class="counter">Increment: ${this.incrementCount}</div> |
| 228 | <p class="hint"> |
| 229 | This prevents repeated triggering while holding the keys down. |
| 230 | Release all keys to allow re-triggering. |
| 231 | </p> |
| 232 | <pre class="code-block"> |
| 233 | ${`@hotkey('Mod+K', { requireReset: true }) |
| 234 | private _handleIncrementing( |
| 235 | _event: KeyboardEvent, |
| 236 | { hotkey }: HotkeyCallbackContext, |
| 237 | ) { |
| 238 | this.incrementCount++ |
| 239 | }`}</pre |
| 240 | > |
| 241 | </section> |
| 242 | |
| 243 | <section class="demo-section"> |
| 244 | <h2>Conditional Hotkey</h2> |
| 245 | <p> |
| 246 | <kbd>${formatForDisplay('Mod+E')}</kbd> is currently |
| 247 | <strong>${this.enabled ? 'enabled' : 'disabled'}</strong> |
| 248 | </p> |
| 249 | <button @click=${() => (this.enabled = !this.enabled)}> |
| 250 | ${this.enabled ? 'Disable' : 'Enable'} Hotkey |
| 251 | </button> |
| 252 | <pre class="code-block"> |
| 253 | ${`@property({ type: Boolean }) enabled = true |
| 254 | |
| 255 | @hotkey('Mod+E') |