win32

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Rendered for windows/amd64

Index

Constants

View Source
const (
	ModAlt = 1 << iota
	ModCtrl
	ModShift
	ModWin
)

Modifiers for Hotkeys

View Source
const (
	KeyeventfExtendedkey = 0x0001
	KeyeventfKeyup       = 0x0002
	KeyeventfUnicode     = 0x0004
	KeyeventfScancode    = 0x0008
)

Keyboard-Input flags

View Source
const (
	KeycodeCtrl      = 0x11
	KeycodeAlt       = 0x12
	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

func SendInput(inputEvents ...Input) error

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

func WaitForWindowChange(ctx context.Context) string

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

func (Hotkey) String

func (h Hotkey) String() string

String returns a human-friendly display name of the hotkey such as "Hotkey[Id: 1, Alt+Ctrl+O]"

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

func KeyDownInput(keycode uint16) Input

KeyDownInput returns the input-struct for pressing the given key (by virtual-keycode)

func KeyDownInputArrowDownSSC added in v0.0.33

func KeyDownInputArrowDownSSC() Input

func KeyUpInput

func KeyUpInput(keycode uint16) Input

KeyUpInput returns the input-struct for releasing the given key (by virtual-keycode)

func KeyUpInputArrowDownSSC added in v0.0.33

func KeyUpInputArrowDownSSC() Input

func UnicodeKeyDownInput

func UnicodeKeyDownInput(keycode uint16) Input

UnicodeKeyDownInput returns the input-struct for pressing the given key (by unicode codepoint)

func UnicodeKeyUpInput

func UnicodeKeyUpInput(keycode uint16) Input

UnicodeKeyUpInput returns the input-struct for releasing the given key (by unicode codepoint)

type KeyboardInput

type KeyboardInput struct {
	VirtualKeyCode uint16
	ScanCode       uint16
	Flags          uint32
	Time           uint32
	ExtraInfo      uint64
}

KeyboardInput describes a keyboard-input event

Jump to

Keyboard shortcuts

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