# Keyboard Support - Test Instructions ## ⚠️ Breaking Change **Version 2.0** uses HTMX configuration objects instead of simple URL strings. The old format is **not supported**. **Old format (no longer supported)**: ```javascript {"A": "/url"} ``` **New format (required)**: ```javascript {"A": {"hx-post": "/url"}} ``` ## Files - `keyboard_support.js` - Main keyboard support library with smart timeout logic - `test_keyboard_support.html` - Test page to verify functionality ## Key Features ### Multiple Simultaneous Triggers **IMPORTANT**: If multiple elements listen to the same combination, **ALL** of them will be triggered: ```javascript add_keyboard_support('modal', '{"esc": "/close-modal"}'); add_keyboard_support('editor', '{"esc": "/cancel-edit"}'); add_keyboard_support('sidebar', '{"esc": "/hide-sidebar"}'); // Pressing ESC will trigger all 3 URLs simultaneously ``` This is crucial for use cases like the ESC key, which often needs to cancel multiple actions at once (close modal, cancel edit, hide panels, etc.). ### Smart Timeout Logic (Longest Match) The library uses **a single global timeout** based on the sequence state, not on individual elements: **Key principle**: If **any element** has a longer sequence possible, **all matching elements wait**. Examples: **Example 1**: Three elements, same combination ```javascript add_keyboard_support('elem1', '{"esc": "/url1"}'); add_keyboard_support('elem2', '{"esc": "/url2"}'); add_keyboard_support('elem3', '{"esc": "/url3"}'); // Press ESC → ALL 3 trigger immediately (no longer sequences exist) ``` **Example 2**: Mixed - one has longer sequence ```javascript add_keyboard_support('elem1', '{"A": "/url1"}'); add_keyboard_support('elem2', '{"A": "/url2"}'); add_keyboard_support('elem3', '{"A": "/url3", "A B": "/url3b"}'); // Press A: // - elem3 has "A B" possible → EVERYONE WAITS 500ms // - If B arrives: only elem3 triggers with "A B" // - If timeout expires: elem1, elem2, elem3 ALL trigger with "A" ``` **Example 3**: Different combinations ```javascript add_keyboard_support('elem1', '{"A B": "/url1"}'); add_keyboard_support('elem2', '{"C D": "/url2"}'); // Press A: elem1 waits for B, elem2 not affected // Press C: elem2 waits for D, elem1 not affected ``` The timeout is tied to the **sequence being typed**, not to individual elements. ### Smart Timeout Logic (Longest Match) Keyboard shortcuts are **disabled** when typing in input fields: - `` elements - `