windows

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Rendered for windows/amd64

Index

Constants

View Source
const (
	WM_GETTEXT       = 0x000D
	WM_GETTEXTLENGTH = 0x000E
	LB_GETCOUNT      = 0x018B
	LB_GETTEXT       = 0x0189
	LB_GETTEXTLEN    = 0x018A
)
View Source
const (
	WM_NULL          = 0x0000
	WM_CLOSE         = 0x0010
	WM_COMMAND       = 0x0111
	WM_KEYDOWN       = 0x0100
	WM_KEYUP         = 0x0101
	WM_SYSKEYDOWN    = 0x0104
	WM_SYSKEYUP      = 0x0105
	SMTO_ABORTIFHUNG = 0x0002
	SMTO_BLOCK       = 0x0003
	BN_CLICKED       = 0

	INPUT_KEYBOARD        = 1
	KEYEVENTF_SCANCODE    = 0x0008
	KEYEVENTF_KEYUP       = 0x0002
	KEYEVENTF_EXTENDEDKEY = 0x0001

	VK_MENU   = 0x12 // Alt key
	VK_F12    = 0x7B
	VK_RETURN = 0x0D

	SC_F12     = 0x58
	SW_RESTORE = 9
	GW_CHILD   = 5

	TOKEN_QUERY    = 0x0008
	TokenElevation = 20
)
View Source
const (
	TH32CS_SNAPPROCESS = 0x00000002
	MAX_PATH           = 260
)
View Source
const (
	CTRL_C_EVENT        = 0
	CTRL_BREAK_EVENT    = 1
	CTRL_CLOSE_EVENT    = 2
	CTRL_LOGOFF_EVENT   = 5
	CTRL_SHUTDOWN_EVENT = 6
)

Console control event types

Variables

View Source
var (
	ProcCreateToolhelp32Snapshot = kernel32.NewProc("CreateToolhelp32Snapshot")
	ProcProcess32First           = kernel32.NewProc("Process32FirstW")
	ProcProcess32Next            = kernel32.NewProc("Process32NextW")
	ProcCloseHandle              = kernel32.NewProc("CloseHandle")

	ProcSendMessageTimeoutW = user32.NewProc("SendMessageTimeoutW")
)
View Source
var MonitorCh chan WindowEvent

Channel to broadcast window events from the monitor

Functions

func CollectChildTexts

func CollectChildTexts(hwnd uintptr) []string

CollectChildTexts retrieves the text of all child windows

func GetClassName

func GetClassName(hwnd uintptr) string

GetClassName retrieves the class name of a window

func GetCtrlTypeName

func GetCtrlTypeName(ctrlType uint32) string

GetCtrlTypeName returns a human-readable name for a control event type

func GetEditText

func GetEditText(hwnd uintptr) string

GetEditText retrieves the text from an Edit control

func GetListBoxItems

func GetListBoxItems(hwnd uintptr) []string

GetListBoxItems retrieves all items from a ListBox control

func GetWindowPid

func GetWindowPid(hwnd uintptr) uint32

GetWindowPid retrieves the process ID of a window

func GetWindowText

func GetWindowText(hwnd uintptr) string

GetWindowText retrieves the text of a window

func IsElevated

func IsElevated() bool

func IsWindow

func IsWindow(hwnd uintptr) bool

IsWindow checks if a window handle is valid

func IsWindowVisible

func IsWindowVisible(hwnd uintptr) bool

IsWindowVisible checks if a window is visible

func RelaunchAsAdmin

func RelaunchAsAdmin() error

func SetConsoleCtrlHandler

func SetConsoleCtrlHandler(handler ConsoleCtrlHandler) error

SetConsoleCtrlHandler sets up a Windows console control handler This catches Ctrl+C, window close, logoff, and shutdown events

func ShellExecute

func ShellExecute(hwnd uintptr, verb, file, args, cwd string, showCmd int) error

ShellExecute executes a file using the Windows shell

func ShellExecuteEx

func ShellExecuteEx(hwnd uintptr, verb, file, args, cwd string, showCmd int, log logger.LoggerInterface) (uint32, error)

ShellExecuteEx executes a file using the Windows shell and returns the process ID This is more reliable than ShellExecute when you need to track the launched process

func TerminateProcess

func TerminateProcess(pid uint32) error

TerminateProcess forcefully terminates a process by its PID

Types

type ChildInfo

type ChildInfo struct {
	Hwnd      uintptr
	ClassName string
	Text      string
	Items     []string // For ListBox controls, stores items directly
}

childInfo and collectChildInfos moved from collect_child_infos.go for single-file build

func CollectChildInfos

func CollectChildInfos(hwnd uintptr) []ChildInfo

CollectChildInfos returns a slice of childInfo for all child controls of hwnd

type Client

type Client struct {
	Window   *windowManager
	Keyboard *keyboardInjector
	Monitor  *monitorManager
	// contains filtered or unexported fields
}

Client provides methods for interacting with Windows APIs It composes specialized managers for different categories of functionality

func NewClient

func NewClient(log logger.LoggerInterface) *Client

NewClient creates a new Windows API client

type ConsoleCtrlHandler

type ConsoleCtrlHandler func(ctrlType uint32) uintptr

ConsoleCtrlHandler is a callback function for console control events

type ControlExtractor

type ControlExtractor func(hwnd uintptr) (text string, items []string)

ControlExtractor is a function that extracts text and items from a specific control type

type HARDWAREINPUT

type HARDWAREINPUT struct {
	UMsg    uint32
	WParamL uint16
	WParamH uint16
}

type INPUT

type INPUT struct {
	Type uint32

	Data [32]byte // Union data (largest is MOUSEINPUT at 24 bytes, padded to 32)
	// contains filtered or unexported fields
}

type KEYBDINPUT

type KEYBDINPUT struct {
	WVk         uint16
	WScan       uint16
	DwFlags     uint32
	Time        uint32
	DwExtraInfo uintptr
}

Structures for SendInput

type MOUSEINPUT

type MOUSEINPUT struct {
	Dx, Dy      int32
	MouseData   uint32
	DwFlags     uint32
	Time        uint32
	DwExtraInfo uintptr
}

type PROCESSENTRY32

type PROCESSENTRY32 struct {
	DwSize              uint32
	CntUsage            uint32
	Th32ProcessID       uint32
	Th32DefaultHeapID   uintptr
	Th32ModuleID        uint32
	CntThreads          uint32
	Th32ParentProcessID uint32
	PcPriClassBase      int32
	DwFlags             uint32
	SzExeFile           [MAX_PATH]uint16
}

type SHELLEXECUTEINFO

type SHELLEXECUTEINFO struct {
	CbSize       uint32
	FMask        uint32
	Hwnd         uintptr
	LpVerb       *uint16
	LpFile       *uint16
	LpParameters *uint16
	LpDirectory  *uint16
	NShow        int32
	HInstApp     uintptr
	LpIDList     uintptr
	LpClass      *uint16
	HkeyClass    uintptr
	DwHotKey     uint32
	HIcon        uintptr
	HProcess     uintptr
}

SHELLEXECUTEINFO for ShellExecuteEx API

type TOKEN_ELEVATION

type TOKEN_ELEVATION struct {
	TokenIsElevated uint32
}

type WindowEvent

type WindowEvent struct {
	Hwnd  uintptr
	Title string
	Pid   uint32
	Class string
}

type WindowInfo

type WindowInfo struct {
	Hwnd  uintptr
	Title string
	Pid   uint32
}

func EnumerateWindows

func EnumerateWindows() []WindowInfo

EnumerateWindows performs a thread-safe enumeration of visible top-level windows

type WindowsAPI

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

WindowsAPI is a concrete implementation of all Windows-related interfaces It wraps a Client to provide the required functionality

func NewWindowsAPI

func NewWindowsAPI(log logger.LoggerInterface) *WindowsAPI

NewWindowsAPI creates a new WindowsAPI with the provided logger

func (*WindowsAPI) CloseWindow

func (w *WindowsAPI) CloseWindow(hwnd uintptr, title string)

WindowManager interface implementation

func (*WindowsAPI) CollectChildInfos

func (w *WindowsAPI) CollectChildInfos(hwnd uintptr) []ChildInfo

func (*WindowsAPI) FindAndClickButton

func (w *WindowsAPI) FindAndClickButton(parentHwnd uintptr, buttonText string) bool

func (*WindowsAPI) GetEditText

func (w *WindowsAPI) GetEditText(hwnd uintptr) string

func (*WindowsAPI) GetListBoxItems

func (w *WindowsAPI) GetListBoxItems(hwnd uintptr) []string

ControlReader interface implementation

func (*WindowsAPI) IsElevated

func (w *WindowsAPI) IsElevated() bool

func (*WindowsAPI) SendAltF12

func (w *WindowsAPI) SendAltF12()

func (*WindowsAPI) SendAltF12ToWindow

func (w *WindowsAPI) SendAltF12ToWindow(hwnd uintptr) bool

func (*WindowsAPI) SendAltF12WithSendInput

func (w *WindowsAPI) SendAltF12WithSendInput() bool

func (*WindowsAPI) SendEnter

func (w *WindowsAPI) SendEnter()

func (*WindowsAPI) SendF12

func (w *WindowsAPI) SendF12()

KeyboardInjector interface implementation

func (*WindowsAPI) SendF12ToWindow

func (w *WindowsAPI) SendF12ToWindow(hwnd uintptr) bool

func (*WindowsAPI) SendF12WithSendInput

func (w *WindowsAPI) SendF12WithSendInput() bool

func (*WindowsAPI) SetForeground

func (w *WindowsAPI) SetForeground(hwnd uintptr) bool

func (*WindowsAPI) VerifyForegroundWindow

func (w *WindowsAPI) VerifyForegroundWindow(expectedHwnd uintptr, expectedPid uint32) bool

func (*WindowsAPI) WaitOnMonitor

func (w *WindowsAPI) WaitOnMonitor(timeout time.Duration, matchers ...func(WindowEvent) bool) (WindowEvent, bool)

Jump to

Keyboard shortcuts

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