Documentation
¶
Overview ¶
Package shortcuts coordinates the family's global shortcuts (spec §10): the canonical way to write a key combination, the conflict rule between two apps' shortcuts, who shows the prompt, and the family's default assignments. Apps declare their shortcuts in their manifest (registry.Manifest.Shortcuts) and check them against the others'.
Index ¶
Constants ¶
const ( Press = "press" // an ordinary key press Tap = "tap" // a modifier tapped alone Double = "double" // double tap Hold = "hold" // hold to talk )
Triggers.
const ( Carbon = "carbon" // RegisterEventHotKey (MyGo GlobalShortcut) EventTap = "eventtap" // a CGEventTap Other = "other" )
Mechanisms.
Variables ¶
var ( TextAlsoUsedBy = family.Text{EN: "Also used by {app} ({function})", ZH: "{app} 已用于“{function}”"} TextConflict = family.Text{ EN: "{keys} is also the {function} shortcut in {app}. Pressing it will trigger both apps.", ZH: "{keys} 同时是 {app} 的“{function}”快捷键,按下时两个 app 都会响应。", } TextChangeShortcut = family.Text{EN: "Change shortcut", ZH: "更改快捷键"} TextOpenSettings = family.Text{EN: "Open {app} settings", ZH: "打开 {app} 设置"} TextIgnore = family.Text{EN: "Ignore", ZH: "忽略"} // TextGlobeKey: an app using Fn alone suggests turning off the 🌐 key's // system action (spec §10.2). TextGlobeKey = family.Text{ EN: "In System Settings → Keyboard, set \"Press 🌐 key to\" to \"Do Nothing\".", ZH: "请在“系统设置 → 键盘”中,把“按下 🌐 键时”设为“无操作”。", } )
Reference texts (spec §10.4).
var Defaults = []Default{ {"auralink", Shortcut{ID: "transcribe", Title: "Transcribe", Keys: "Fn", Trigger: Tap, Enabled: true, Mechanism: EventTap, Exclusive: true}}, {"auralink", Shortcut{ID: "translate", Title: "Translate", Keys: "Fn+Shift", Trigger: Tap, Enabled: true, Mechanism: EventTap}}, {"auralink", Shortcut{ID: "rewrite", Title: "Rewrite", Keys: "Fn+Control", Trigger: Tap, Enabled: true, Mechanism: EventTap}}, {"auralink", Shortcut{ID: "pasteLast", Title: "Paste last", Keys: "Control+Command+V", Trigger: Press, Enabled: true, Mechanism: EventTap, Exclusive: true}}, {"voxtnew", Shortcut{ID: "transcribe", Title: "Transcribe", Keys: "RightOption", Trigger: Tap, Enabled: true, Mechanism: EventTap}}, {"voxtnew", Shortcut{ID: "translate", Title: "Translate", Keys: "RightOption+Shift", Trigger: Tap, Enabled: true, Mechanism: EventTap}}, {"voxtnew", Shortcut{ID: "rewrite", Title: "Rewrite", Keys: "Control+RightOption", Trigger: Tap, Enabled: true, Mechanism: EventTap}}, {"voxtnew", Shortcut{ID: "pasteLast", Title: "Paste last", Keys: "Control+Option+V", Trigger: Press, Enabled: true, Mechanism: EventTap, Exclusive: true}}, {"audiosmith", Shortcut{ID: "dictation", Title: "Dictation", Keys: "Shift+Command+Space", Trigger: Press, Enabled: true, Mechanism: Carbon}}, {"dicta", Shortcut{ID: "meeting", Title: "Start / stop meeting notes", Keys: "Control+Option+Command+R", Trigger: Press, Enabled: false, Mechanism: Carbon}}, {"pik", Shortcut{ID: "openPicker", Title: "Open Picker", Keys: "Control+Option+Command+P", Trigger: Press, Enabled: true, Mechanism: Carbon}}, {"pik", Shortcut{ID: "openColorPanel", Title: "Open Color Panel", Keys: "Control+Option+Command+C", Trigger: Press, Mechanism: Carbon}}, {"pik", Shortcut{ID: "openStatusMenu", Title: "Open Status Menu", Keys: "Control+Option+Command+M", Trigger: Press, Mechanism: Carbon}}, {"pik", Shortcut{ID: "openPikMenu", Title: "Open Pik Menu", Keys: "Control+Option+Shift+Command+M", Trigger: Press, Mechanism: Carbon}}, {"pik", Shortcut{ID: "openContrastChecker", Title: "Open Contrast Checker", Keys: "Control+Option+Command+O", Trigger: Press, Mechanism: Carbon}}, {"pik", Shortcut{ID: "toggleColorDock", Title: "Show/Hide Color Dock", Keys: "Control+Option+Command+D", Trigger: Press, Mechanism: Carbon}}, {"pik", Shortcut{ID: "getPrimaryColor", Title: "Get Primary Color", Keys: "Control+Option+Command+F", Trigger: Press, Mechanism: Carbon}}, {"pik", Shortcut{ID: "getSecondaryColor", Title: "Get Secondary Color", Keys: "Control+Option+Command+B", Trigger: Press, Mechanism: Carbon}}, {"pik", Shortcut{ID: "pickArea", Title: "Pick Area", Keys: "Control+Option+Command+A", Trigger: Press, Mechanism: Carbon}}, {"herenow", Shortcut{ID: "openPanel", Title: "Open HereNow", Keys: "Control+Option+Command+H", Trigger: Press, Enabled: true, Mechanism: Carbon}}, {"refto", Shortcut{ID: "quickCollect", Title: "Quick Collect", Keys: "Control+Option+Command+S", Trigger: Press, Enabled: true, Mechanism: Carbon}}, {"inboxly", Shortcut{ID: "quickCompose", Title: "Quick Compose", Keys: "Control+Option+Command+N", Trigger: Press, Enabled: true, Mechanism: Carbon}}, }
Defaults is the family's default shortcut table. Disabled rows are reserved: they must not collide either, since users may turn them on.
var ErrEmpty = errors.New("empty shortcut")
ErrEmpty: no keys.
Functions ¶
func Conflicts ¶
Conflicts reports whether two enabled shortcuts collide (spec §10.4). The trigger does not matter: a tap of Fn and a hold of Fn both fire on Fn.
func NormalizeTrigger ¶
NormalizeTrigger maps the apps' trigger names to the spec's: Auralink's "long" is Hold; "" is Press.
Types ¶
type Combo ¶
type Combo struct {
// Mods has, for each modifier, the sides required: nil = not part of
// the combination.
Mods [numMods][]Side
Key string // MyGo accelerator key name ("V", "Space", "F5"); "" = modifiers only
}
Combo is a parsed key combination.
type Conflict ¶
type Conflict struct {
Mine Shortcut
Other Holder // the other app (all its shortcuts)
Theirs Shortcut
// Prompt: I am the later one (set or enabled it after them), so I
// show the prompt (TextConflict); otherwise only the warning on the
// settings row (spec §10.4). Remember shown prompts per pair.
Prompt bool
}
Conflict is one of my shortcuts colliding with another app's.
func FindConflicts ¶
FindConflicts lists my shortcuts' conflicts with the other installed apps' (spec §10.4). Pass installed apps whether or not they run: they may start at login.
type Default ¶
Default is a row of the family's default assignment (spec §10.2): new apps check it before choosing defaults; exclusive (event-swallowing) keys go to one app only — Fn belongs to Auralink.
type Holder ¶
type Holder struct {
BundleID string
Name string // "Auralink"
Updated time.Time // the manifest's updated: when a shortcut has no EnabledAt
Links map[string]string // the manifest's links ("shortcuts": its settings page)
Shortcuts []Shortcut
}
Holder is an app and its declared shortcuts (from its manifest).
type Shortcut ¶
type Shortcut struct {
ID string `json:"id"` // the app's function id: "transcribe"
Title string `json:"title"` // English function name, shown in conflict prompts
Keys string `json:"keys"` // canonical (Normalize): "Control+Command+V", "RightOption"
Trigger string `json:"trigger"`
Enabled bool `json:"enabled"`
Mechanism string `json:"mechanism"`
Exclusive bool `json:"exclusive"` // swallows the key events
// EnabledAt is when the user turned it on or set its keys: the later
// of two conflicting apps shows the prompt.
EnabledAt *time.Time `json:"enabledAt,omitempty"`
Extra family.Extra `json:"-"`
}
Shortcut is a global shortcut an app declares (spec §10.3).
func DefaultsOf ¶
DefaultsOf lists an app's default shortcuts.