keycodes
keycodes
¶
macOS key codes and modifier flags for the global dictation hotkey.
Pure data + classification, deliberately importable without PyObjC so the
push-to-talk state machine can be unit-tested headlessly. The live event tap
(hotkey.py) maps real CGEvents onto the vocabulary defined here.
Functions:¶
normalize_hotkey
¶
Return a supported hotkey name, falling back to the default.
Mirrors the forgiving parse Diapason applies to its hotkey setting: an
unknown or empty value must not leave dictation unbound, it falls back to
Control.
Source code in src/diapason/desktop/keycodes.py
keycode_matches
¶
True when keycode is one of the physical keys for hotkey.
is_bare_press
¶
True when flags show the bound modifier down and no OTHER modifier.
A push-to-talk key must fire on the key alone. If the user is holding Command as well (Cmd+Control), that is a chord meant for the app in front, not a dictation trigger, so we let it through untouched.
Source code in src/diapason/desktop/keycodes.py
classify_flags_change
¶
Interpret a flagsChanged event as "down", "up" or None.
macOS reports modifier presses as flagsChanged events carrying the new
flag state, not as key-down/up. The bound key is down when its own flag
bit is set on an event for its keycode, and up when the same keycode
arrives with its bit cleared.