# Keyboard Coordinator


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Coordinator Setup

The coordinator is a global singleton (`window.kbCoordinator`) that
manages registration, hierarchy, and event dispatch for all keyboard
systems on a page. Each keyboard system registers its handler instead of
adding its own `document.keydown` listener. The coordinator owns the
single listener and routes events through the parent-child hierarchy:
deepest active child handles first, unhandled events bubble up.

------------------------------------------------------------------------

<a
href="https://github.com/cj-mills/cjm-fasthtml-keyboard-navigation/blob/main/cjm_fasthtml_keyboard_navigation/js/coordinator.py#L12"
target="_blank" style="float:right; font-size:smaller">source</a>

### js_coordinator_setup

``` python

def js_coordinator_setup(
    
)->str: # JavaScript coordinator singleton code

```

*Generate the global keyboard coordinator singleton.*

``` python
# Test coordinator JS generation
result = js_coordinator_setup()
assert "window.kbCoordinator" in result
assert "register" in result
assert "setParent" in result
assert "setActiveChild" in result
assert "deactivateChild" in result
assert "_handleKeydown" in result
assert "_buildActiveChain" in result
assert "validateActiveChildren" in result
assert "_notifyActivation" in result
assert "_notifyDeactivation" in result
# Pause/resume API
assert "pause:" in result
assert "resume:" in result
assert "isPaused:" in result
assert "_paused" in result
```
