Shortcuts

Process-wide hot keys, through Carbon's RegisterEventHotKey. The plugin is named shortcut (singular) and macOS registers it, so a page can call it directly.

register

const result = await window.crust.invoke("shortcut", "register", {
	accelerator: "CommandOrControl+Shift+K",
});
// { ok: true, accelerator: "command+shift+k" }

A registration answers the canonical spelling, and that is the name every other command matches, so Cmd+Shift+K and command+shift+k are one hot key and a second registration of either is refused.

The accelerator is modifiers, then the key, joined by +:

partaccepted
modifiercommand, control, option, shift; aliases cmd, cmdorctrl, commandorcontrol, ctrl, alt, opt
keya–z, 0–9, f1–f19, the named keys escape tab space enter backspace forwarddelete insert home end pageup pagedown up down left right, the punctuation - = [ ] ; ' , . / and the backtick

The last token is the key and everything before it is a modifier. Canonical order is command, control, option, shift. At least one modifier is required: a bare key would be registered globally with no modifier and swallow every press of that key in every app, so it is a bad-accelerator.

The press

A hot key fires outside any command, so it arrives as an event:

const off = window.crust.listen("shortcut", ({ accelerator }) => {
	console.log(accelerator); // "command+shift+k"
});

The event carries the canonical accelerator, and it fires whether or not the app is frontmost — that is what makes it global. off() unsubscribes.

Commands

commandargumentsanswers
register{ accelerator }{ ok: true, accelerator }
unregister{ accelerator }{ ok: true, accelerator }
unregisterAllnone{ removed }
isRegistered{ accelerator }boolean
listnonecanonical accelerators

isRegistered answers false for a malformed accelerator instead of a failure, and list reads the registry the plugin owns, so neither needs an OS round-trip.

Failure codes

codewhen
bad-acceleratora token the grammar has no name for; part is that token, verbatim
already-registeredthis process already holds that canonical accelerator
not-registeredunregister named one nothing holds
native-failedRegisterEventHotKey refused, or the C unit would not compile
not-implementedno adapter, so nothing can reach the window server

bad-accelerator and native-failed carry part when a token can be named, so a settings UI can point at the broken piece rather than quoting the whole string.