Documentation
¶
Index ¶
- Constants
- func GetForegroundWindow() string
- func ListenForHotkeys(ctx context.Context, handler HotkeyHandler, hotkeys ...*Hotkey) error
- func SendInput(inputEvents ...Input) error
- func SendString(s string)
- func WaitForWindowChange(ctx context.Context) string
- type Hotkey
- type HotkeyHandler
- type Input
- type KeyboardInput
Constants ¶
const ( ModAlt = 1 << iota ModCtrl ModShift ModWin )
Modifiers for Hotkeys
const ( KeyeventfExtendedkey = 0x0001 KeyeventfKeyup = 0x0002 KeyeventfUnicode = 0x0004 KeyeventfScancode = 0x0008 )
Keyboard-Input flags
const ( KeycodeCtrl = 0x11 KeycodeReturn = 0x0D KeycodeShift = 0x10 KeycodeBackspace = 0x08 KeycodeDown = 0x28 KeycodeUp = 0x26 KeycodeRight = 0x27 KeycodeLeft = 0x25 KeycodeDelete = 0x2E KeycodeEnd = 0x23 )
Constants for special keycodes
Variables ¶
This section is empty.
Functions ¶
func GetForegroundWindow ¶
func GetForegroundWindow() string
GetForegroundWindow returns the name of the window that currently has the user-focus
func ListenForHotkeys ¶
func ListenForHotkeys(ctx context.Context, handler HotkeyHandler, hotkeys ...*Hotkey) error
ListenForHotkeys registers an listens for the given global Hotkeys. If a hotkey is pressed, the hendler function is executed This function blocks, so it shoue have it's own goroutine
func SendInput ¶
SendInput is a go-wrapper for the win32 SendInput function. It sends input events to the currently active window
func SendString ¶
func SendString(s string)
SendString sends input-events to the OS, that simulate typing the given string
func WaitForWindowChange ¶
WaitForWindowChange blocks until the window with the user-focus changes (or ctx is cancelled). Returns the title of the new active window
Types ¶
type Hotkey ¶
type Hotkey struct {
// Id, must be unique for each registered hotkey
ID int // Unique id
// Modifiers is a bitmask containing modifiers for the hotkey
Modifiers int // Mask of modifiers
// KeyCode is the keycode for the hotkey
KeyCode int // Key code, e.g. 'A'
}
Hotkey represents a key-combination pressed by a user
type HotkeyHandler ¶
type HotkeyHandler func(Hotkey)
HotkeyHandler is the callback for registered hotkeys
type Input ¶
type Input struct {
InputType uint32
KeyboardInput KeyboardInput
Padding uint64
}
Input describes an input-event
func KeyDownInput ¶
KeyDownInput returns the input-struct for pressing the given key (by virtual-keycode)
func KeyUpInput ¶
KeyUpInput returns the input-struct for releasing the given key (by virtual-keycode)
func UnicodeKeyDownInput ¶
UnicodeKeyDownInput returns the input-struct for pressing the given key (by unicode codepoint)
func UnicodeKeyUpInput ¶
UnicodeKeyUpInput returns the input-struct for releasing the given key (by unicode codepoint)