hotkeys

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HotkeyProvider

type HotkeyProvider interface {
	StartHook() error
	Unhook() error
}

HotkeyProvider must be implemented by any OS specific hotkey system to be used by the hotkeys.Service

func SetupHotkeys

func SetupHotkeys() (HotkeyProvider, chan KeyInfo)

type KeyInfo

type KeyInfo struct {
	KeyCode    int
	LocaleName string
}

KeyInfo is the Go-friendly struct to capture key code and key name data from the OS

type Service

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

Service holds a channel that retrieves KeyInfo, controls the provided HotkeyProvider with StartHook/Unhook, and calls exported functions on the provided Splitter (usually session.Service if not testing)

func NewService

func NewService(keyInfoChannel chan KeyInfo, sessionService Splitter, provider HotkeyProvider) *Service

NewService creates a new hotkeys.Service that holds a chan KeyInfo, a reference to a Splitter (usually session.Service) a HotkeyProvider that sends raw keypresses from the OS to the keyInfoChannel

The common pattern used in OpenSplit is to create a HotkeyProvider with a constructor func that also returns a chan KeyInfo it sends keypress information to, and use that as the first parameter to this constructor func.

func (*Service) StartDispatcher

func (s *Service) StartDispatcher()

StartDispatcher creates an internal channel that shuts down the dispatch loop when closed, starts the HotkeyProvider OS Hook, and starts the dispatch loop that listens on hotkeyChannel for KeyInfo events

func (*Service) StopDispatcher

func (s *Service) StopDispatcher()

StopDispatcher unhooks the HotkeyProvider from the OS, and closes the internal stop channel to stop the dispatch loop

type Splitter

type Splitter interface {
	Split()
}

Splitter is generally implemented by the session.Service created by the application, but this interface is useful for testing purposes

Jump to

Keyboard shortcuts

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