Skip to content

keycodes

diapason.desktop.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.

classify_flags_change(hotkey, keycode, flags)

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.

is_bare_press(hotkey, flags)

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.

keycode_matches(hotkey, keycode)

True when keycode is one of the physical keys for hotkey.

normalize_hotkey(name)

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.