hotkey

package
v0.40.4 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package hotkey is the Windows adapter for the global hotkey bus. Dictation, Assist, and Voice Agent each register a binding here; the package translates RegisterHotKey/UnregisterHotKey Win32 calls into channel events the desktop runtime consumes.

Combo syntax (ParseCombo): `+`-separated tokens, e.g. `ctrl+shift`, `win+alt`, `ctrl+alt+f12`, `ctrl+space`. Mouse side-buttons X1/X2 are recognised as `mouse-x1`/`mouse-x2` (aliases `mb4`/`mb5`) and picked up by the polling loop via GetAsyncKeyState — no separate WH_MOUSE_LL hook is installed. Left, right, and middle mouse buttons are intentionally NOT mappable to keep everyday clicks usable.

Audit 2026-05-24 maintainability sweep.

Index

Constants

View Source
const (
	VkBackspace = 0x08
	VkTab       = 0x09
	VkReturn    = 0x0D
	VkEscape    = 0x1B
	VkSpace     = 0x20

	VkLShift   = 0xA0
	VkRShift   = 0xA1
	VkLControl = 0xA2
	VkRControl = 0xA3
	VkLMenu    = 0xA4 // Left Alt
	VkRMenu    = 0xA5 // Right Alt
	VkLWin     = 0x5B
	VkRWin     = 0x5C
	VkShift    = 0x10
	VkControl  = 0x11
	VkMenu     = 0x12 // Alt

	// Mouse side-buttons (X1/X2). Used by the v0.39.0 custom-binding picker
	// so users can bind Dictation/Assist/VoiceAgent to e.g. `mouse-x1` or
	// `ctrl+mouse-x2`. The poll loop picks them up via GetAsyncKeyState — no
	// separate WH_MOUSE_LL hook is installed in this iteration. Left/right/
	// middle mouse buttons are intentionally NOT mapped because binding them
	// would block everyday clicks.
	VkXButton1 = 0x05
	VkXButton2 = 0x06
)

Virtual key codes

Variables

This section is empty.

Functions

func ComboAlt

func ComboAlt() []uint32

ComboAlt returns VK code for Alt.

func ComboCtrlShift

func ComboCtrlShift() []uint32

ComboCtrlShift returns VK codes for Ctrl+Shift.

func ComboF8

func ComboF8() []uint32

ComboF8 returns VK code for F8.

func ComboWinAlt

func ComboWinAlt() []uint32

ComboWinAlt returns VK codes for Win+Alt.

func ParseCombo

func ParseCombo(s string) []uint32

ParseCombo parses strings like "alt" or "ctrl+shift+d" into VK codes.

Types

type Event

type Event struct {
	Type    EventType
	Binding string

	// Source identifies the origin of this event. Native keyboard-hook
	// events leave this zero (empty string) which callers must treat as
	// equivalent to EventSourceHotkey. Synthesized events (wake-word,
	// future programmatic triggers) set this explicitly.
	Source EventSource
}

type EventSource added in v0.35.8

type EventSource string

EventSource identifies the origin of a hotkey event.

const (
	// EventSourceHotkey is the default — the event came from a real
	// keyboard press picked up by the platform hotkey manager.
	EventSourceHotkey EventSource = "hotkey"

	// EventSourceWakeword indicates the event was synthesized by the
	// wake-word adapter to simulate a hotkey press. Consumers that need
	// different downstream behaviour for wake-word-triggered activations
	// (e.g. attach an AutoEndPolicy, ignore hold-to-talk semantics)
	// branch on this value.
	EventSourceWakeword EventSource = "wakeword"
)

type EventType

type EventType int
const (
	EventKeyDown EventType = iota
	EventKeyUp
)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager captures a push-to-talk key combination through a low-level keyboard hook.

func NewManager

func NewManager(combo []uint32) *Manager

NewManager creates a PTT manager. combo is a list of VK codes that must ALL be pressed.

func (*Manager) Events

func (m *Manager) Events() <-chan Event

func (*Manager) Reconfigure

func (m *Manager) Reconfigure(combo []uint32)

Reconfigure swaps the key combination while the hook is running. The keyboard hook stays installed; only the combo tracker is replaced.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start installs a low-level keyboard hook and emits key down/up events for the configured combo.

func (*Manager) Stop

func (m *Manager) Stop()

Jump to

Keyboard shortcuts

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