Documentation
¶
Index ¶
- Constants
- Variables
- func CollectChildTexts(hwnd uintptr) []string
- func GetClassName(hwnd uintptr) string
- func GetCtrlTypeName(ctrlType uint32) string
- func GetEditText(hwnd uintptr) string
- func GetListBoxItems(hwnd uintptr) []string
- func GetWindowPid(hwnd uintptr) uint32
- func GetWindowText(hwnd uintptr) string
- func IsElevated() bool
- func IsWindow(hwnd uintptr) bool
- func IsWindowVisible(hwnd uintptr) bool
- func RelaunchAsAdmin() error
- func SetConsoleCtrlHandler(handler ConsoleCtrlHandler) error
- func ShellExecute(hwnd uintptr, verb, file, args, cwd string, showCmd int) error
- func ShellExecuteEx(hwnd uintptr, verb, file, args, cwd string, showCmd int, ...) (uint32, error)
- func TerminateProcess(pid uint32) error
- type ChildInfo
- type Client
- type ConsoleCtrlHandler
- type ControlExtractor
- type HARDWAREINPUT
- type INPUT
- type KEYBDINPUT
- type MOUSEINPUT
- type PROCESSENTRY32
- type SHELLEXECUTEINFO
- type TOKEN_ELEVATION
- type WindowEvent
- type WindowInfo
- type WindowsAPI
- func (w *WindowsAPI) CloseWindow(hwnd uintptr, title string)
- func (w *WindowsAPI) CollectChildInfos(hwnd uintptr) []ChildInfo
- func (w *WindowsAPI) FindAndClickButton(parentHwnd uintptr, buttonText string) bool
- func (w *WindowsAPI) GetEditText(hwnd uintptr) string
- func (w *WindowsAPI) GetListBoxItems(hwnd uintptr) []string
- func (w *WindowsAPI) IsElevated() bool
- func (w *WindowsAPI) SendAltF12()
- func (w *WindowsAPI) SendAltF12ToWindow(hwnd uintptr) bool
- func (w *WindowsAPI) SendAltF12WithSendInput() bool
- func (w *WindowsAPI) SendEnter()
- func (w *WindowsAPI) SendF12()
- func (w *WindowsAPI) SendF12ToWindow(hwnd uintptr) bool
- func (w *WindowsAPI) SendF12WithSendInput() bool
- func (w *WindowsAPI) SetForeground(hwnd uintptr) bool
- func (w *WindowsAPI) VerifyForegroundWindow(expectedHwnd uintptr, expectedPid uint32) bool
- func (w *WindowsAPI) WaitOnMonitor(timeout time.Duration, matchers ...func(WindowEvent) bool) (WindowEvent, bool)
Constants ¶
const ( WM_GETTEXT = 0x000D WM_GETTEXTLENGTH = 0x000E LB_GETCOUNT = 0x018B LB_GETTEXT = 0x0189 LB_GETTEXTLEN = 0x018A )
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 )
const ( TH32CS_SNAPPROCESS = 0x00000002 MAX_PATH = 260 )
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 ¶
var ( ProcCreateToolhelp32Snapshot = kernel32.NewProc("CreateToolhelp32Snapshot") ProcProcess32First = kernel32.NewProc("Process32FirstW") ProcProcess32Next = kernel32.NewProc("Process32NextW") ProcCloseHandle = kernel32.NewProc("CloseHandle") ProcSendMessageTimeoutW = user32.NewProc("SendMessageTimeoutW") )
var MonitorCh chan WindowEvent
Channel to broadcast window events from the monitor
Functions ¶
func CollectChildTexts ¶
CollectChildTexts retrieves the text of all child windows
func GetClassName ¶
GetClassName retrieves the class name of a window
func GetCtrlTypeName ¶
GetCtrlTypeName returns a human-readable name for a control event type
func GetEditText ¶
GetEditText retrieves the text from an Edit control
func GetListBoxItems ¶
GetListBoxItems retrieves all items from a ListBox control
func GetWindowPid ¶
GetWindowPid retrieves the process ID of a window
func GetWindowText ¶
GetWindowText retrieves the text of a window
func IsElevated ¶
func IsElevated() bool
func IsWindowVisible ¶
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 ¶
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 ¶
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 ¶
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 ¶
ConsoleCtrlHandler is a callback function for console control events
type ControlExtractor ¶
ControlExtractor is a function that extracts text and items from a specific control type
type HARDWAREINPUT ¶
type KEYBDINPUT ¶
Structures for SendInput
type MOUSEINPUT ¶
type PROCESSENTRY32 ¶
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 WindowInfo ¶
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)