shortcuts

package
v0.23.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	Press  = "press"  // an ordinary key press
	Tap    = "tap"    // a modifier tapped alone
	Double = "double" // double tap
	Hold   = "hold"   // hold to talk
)

Triggers.

View Source
const (
	Carbon   = "carbon"   // RegisterEventHotKey (MyGo GlobalShortcut)
	EventTap = "eventtap" // a CGEventTap
	Other    = "other"
)

Mechanisms.

Variables

View Source
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).

View Source
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.

View Source
var ErrEmpty = errors.New("empty shortcut")

ErrEmpty: no keys.

Functions

func Conflicts

func Conflicts(a, b Shortcut) bool

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 Normalize

func Normalize(keys string) (string, error)

Normalize is Parse then String.

func NormalizeTrigger

func NormalizeTrigger(t string) string

NormalizeTrigger maps the apps' trigger names to the spec's: Auralink's "long" is Hold; "" is Press.

func Overlap

func Overlap(a, b Combo) bool

Overlap reports whether two combinations would fire on the same keys: the same key and the same modifiers, where Option matches LeftOption and RightOption, and LeftOption does not match RightOption.

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.

func Parse

func Parse(keys string) (Combo, error)

Parse reads a key combination in any of the apps' spellings: "CmdOrCtrl+Shift+Space", "Super+Ctrl+Alt+P", "fn+shift", "globe", "RightOption", "⌃⌘V".

func (Combo) String

func (c Combo) String() string

String is the canonical form (spec §10.3): modifiers in the order Fn, Control, Option, Shift, Command, sides as LeftOption / RightCommand, then the key, joined with "+".

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

func FindConflicts(me Holder, others []Holder) []Conflict

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.

func (Conflict) Key

func (c Conflict) Key() string

Key identifies a conflict pair for "shown once" bookkeeping.

type Default

type Default struct {
	App string // app id
	Shortcut
}

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 Hit

type Hit struct {
	App      Holder
	Shortcut Shortcut
}

Hit is another app's shortcut on the keys being recorded.

func UsedBy

func UsedBy(keys string, self string, others []Holder) []Hit

UsedBy checks keys being recorded against the other apps' enabled shortcuts, for "Also used by Auralink (Transcribe)" under the recorder (TextAlsoUsedBy). Saving stays allowed.

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 Mod

type Mod int

Mod is a modifier key.

const (
	Fn Mod = iota
	Control
	Option
	Shift
	Command
)

func (Mod) String

func (m Mod) String() string

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

func DefaultsOf(app string) []Shortcut

DefaultsOf lists an app's default shortcuts.

func (Shortcut) MarshalJSON

func (s Shortcut) MarshalJSON() ([]byte, error)

func (*Shortcut) UnmarshalJSON

func (s *Shortcut) UnmarshalJSON(b []byte) error

type Side

type Side int

Side of a modifier: either, or one of the two keys.

const (
	Either Side = iota
	Left
	Right
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL