Skip to content

hotkey

diapason.desktop.hotkey

Global push-to-talk hotkey via a CGEventTap.

tauri-plugin-global-shortcut cannot listen for a bare held modifier — it only accepts a full accelerator (Cmd+Shift+X). Diapason solved this with a compiled Objective-C++ CGEventTap; here the same tap is driven from Python through PyObjC, so it needs no separate native module and works whether or not the Tauri GUI is running.

The event classification lives in keycodes.py and is fully tested. This module is the thin live layer: it creates the tap, pumps a run loop on a background thread, and calls on_down / on_up when the bound key transitions. Creating the tap requires Accessibility permission (AXIsProcessTrusted); without it macOS returns a null tap, which we surface as a clear error rather than silent dead keys.

AccessibilityError

Bases: RuntimeError

Raised when the event tap cannot be created (permission not granted).

HotkeyListener

Fire on_down/on_up when the bound modifier is pressed/released.

start()

Create the tap and pump its run loop on a daemon thread.