win32

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Rendered for windows/amd64

Overview

Package win32 provides Windows API bindings using purego/syscall, eliminating the need for cgo.

Index

Constants

View Source
const (
	INPUT_MOUSE    = 0
	INPUT_KEYBOARD = 1

	MOUSEEVENTF_MOVE       = 0x0001
	MOUSEEVENTF_LEFTDOWN   = 0x0002
	MOUSEEVENTF_LEFTUP     = 0x0004
	MOUSEEVENTF_RIGHTDOWN  = 0x0008
	MOUSEEVENTF_RIGHTUP    = 0x0010
	MOUSEEVENTF_MIDDLEDOWN = 0x0020
	MOUSEEVENTF_MIDDLEUP   = 0x0040
	MOUSEEVENTF_WHEEL      = 0x0800
	MOUSEEVENTF_HWHEEL     = 0x01000

	KEYEVENTF_KEYUP    = 0x0002
	KEYEVENTF_UNICODE  = 0x0004
	KEYEVENTF_SCANCODE = 0x0008

	WHEEL_DELTA = 120

	MAPVK_VK_TO_VSC    = 0
	MAPVK_VSC_TO_VK    = 1
	MAPVK_VK_TO_CHAR   = 2
	MAPVK_VSC_TO_VK_EX = 3

	VK_LSHIFT   = 0xA0
	VK_RSHIFT   = 0xA1
	VK_LCONTROL = 0xA2
	VK_RCONTROL = 0xA3
	VK_LMENU    = 0xA4
	VK_RMENU    = 0xA5
	VK_LWIN     = 0x5B
	VK_RWIN     = 0x5C

	SW_MINIMIZE = 6
	SW_MAXIMIZE = 3
	SW_RESTORE  = 9

	GWL_STYLE   = -16
	WS_MAXIMIZE = 0x01000000
	WS_MINIMIZE = 0x20000000

	WM_CLOSE         = 0x0010
	WM_GETTEXT       = 0x000D
	WM_GETTEXTLENGTH = 0x000E

	DIB_RGB_COLORS = 0
	SRCCOPY        = 0x00CC0020
	BI_RGB         = 0

	GWL_WNDPROC = -4
	WM_KEYDOWN  = 0x0100
	WM_KEYUP    = 0x0101
	WM_CHAR     = 0x0102
)

Windows constants

Variables

This section is empty.

Functions

func CaptureScreen

func CaptureScreen(x, y, w, h int32) ([]byte, int, int)

CaptureScreen captures a screen region and returns pixel data (BGRA format) The caller is responsible for freeing the returned buffer.

func CloseWindow

func CloseWindow(hwnd uintptr) bool

CloseWindow minimizes a window

func EnumWindows

func EnumWindows(callback uintptr, lParam uintptr) bool

EnumWindows enumerates all top-level windows

func FindWindowByName

func FindWindowByName(name string) uintptr

FindWindowByName finds a window by name

func FindWindowByPID

func FindWindowByPID(pid uint32) uintptr

FindWindowByPID finds a window by process ID

func GetActiveWindow

func GetActiveWindow() uintptr

GetActiveWindow gets the active window

func GetCursorPos

func GetCursorPos(pt *POINT) bool

GetCursorPos gets the cursor position

func GetDesktopWindow

func GetDesktopWindow() uintptr

GetDesktopWindow gets the desktop window

func GetDpiForWindow

func GetDpiForWindow(hwnd uintptr) uint32

GetDpiForWindow gets DPI for a window

func GetForegroundWindow

func GetForegroundWindow() uintptr

GetForegroundWindow returns the foreground window handle

func GetNumDisplays

func GetNumDisplays() int

GetNumDisplays gets the number of displays

func GetPixelColor

func GetPixelColor(x, y int32) uint32

GetPixelColor gets the pixel color at (x, y) as RGB hex

func GetScreenSize

func GetScreenSize() (int32, int32)

GetScreenSize gets the main display size

func GetSystemMetricsForDpi

func GetSystemMetricsForDpi(idx int32, dpi uint32) int32

GetSystemMetricsForDpi gets system metrics for DPI

func GetWindowText

func GetWindowText(hwnd uintptr) string

GetWindowText gets the window title

func GetWindowThreadProcessId

func GetWindowThreadProcessId(hwnd uintptr) uint32

GetWindowThreadProcessId gets the thread and process id for a window

func IsWindow

func IsWindow(hwnd uintptr) bool

IsWindow checks if a window handle is valid

func KeyCodeForChar

func KeyCodeForChar(char byte) uint32

KeyCodeForChar returns the virtual key code for a character

func MapVirtualKey

func MapVirtualKey(uCode, uMapType uint32) uint32

MapVirtualKey maps a virtual key code

func MoveMouse

func MoveMouse(x, y int32) int

MoveMouse moves the mouse cursor to (x, y)

func PostCloseMessage

func PostCloseMessage(hwnd uintptr)

PostCloseMessage posts WM_CLOSE to a window

func ScrollMouse

func ScrollMouse(x, y int)

ScrollMouse scrolls the mouse wheel

func SendInput

func SendInput(nInputs uint32, pInputs unsafe.Pointer, cbSize int32) uint32

SendInput sends input events

func SetActiveWindowHwnd

func SetActiveWindowHwnd(hwnd uintptr) uintptr

SetActiveWindowHwnd sets the active window

func SetCursorPos

func SetCursorPos(x, y int32) bool

SetCursorPos sets the cursor position

func SetFocusHwnd

func SetFocusHwnd(hwnd uintptr) uintptr

SetFocusHwnd sets the window focus

func SetForegroundWindow

func SetForegroundWindow(hwnd uintptr) bool

SetForegroundWindow sets the foreground window

func SetWindowPlacement

func SetWindowPlacement(hwnd uintptr, wp *WINDOWPLACEMENT) bool

SetWindowPlacement sets the window placement

func ShowWindow

func ShowWindow(hwnd uintptr, cmd int32) bool

ShowWindow shows/hides/minimizes/maximizes a window

func ToggleKeyCode

func ToggleKeyCode(keyCode uint32, down bool, flags uint64, pid uintptr) int

ToggleKeyCode sends a key down/up event

func ToggleMouse

func ToggleMouse(down bool, button uint16) int

ToggleMouse toggles a mouse button (down or up)

func UnicodeType

func UnicodeType(char uint32, pid uintptr, isPid int8)

UnicodeType sends a unicode character

Types

type BITMAPINFOHEADER

type BITMAPINFOHEADER struct {
	BiSize          uint32
	BiWidth         int32
	BiHeight        int32
	BiPlanes        uint16
	BiBitCount      uint16
	BiCompression   uint32
	BiSizeImage     uint32
	BiXPelsPerMeter int32
	BiYPelsPerMeter int32
	BiClrUsed       uint32
	BiClrImportant  uint32
}

BITMAPINFOHEADER is the Windows BITMAPINFOHEADER structure

type INPUT

type INPUT struct {
	Type uint32
	Di   [24]byte // large enough for MOUSEINPUT + KEYBDINPUT
}

INPUT is the Windows INPUT structure for SendInput

type KEYBDINPUT

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

KEYBDINPUT is the Windows KEYBDINPUT structure

type MOUSEINPUT

type MOUSEINPUT struct {
	DX          int32
	DY          int32
	MouseData   uint32
	DwFlags     uint32
	Time        uint32
	DwExtraInfo uintptr
}

MOUSEINPUT is the Windows MOUSEINPUT structure

type POINT

type POINT struct {
	X int32
	Y int32
}

POINT is the Windows POINT structure

type RECT

type RECT struct {
	Left   int32
	Top    int32
	Right  int32
	Bottom int32
}

RECT is the Windows RECT structure

func GetClientRect

func GetClientRect(hwnd uintptr) (RECT, bool)

GetClientRect gets the window client rectangle

func GetWindowRect

func GetWindowRect(hwnd uintptr) (RECT, bool)

GetWindowRect gets the window rectangle

type WINDOWPLACEMENT

type WINDOWPLACEMENT struct {
	Length           uint32
	Flags            uint32
	ShowCmd          uint32
	PtMinPosition    POINT
	PtMaxPosition    POINT
	RcNormalPosition RECT
}

WINDOWPLACEMENT is the Windows WINDOWPLACEMENT structure

func GetWindowPlacement

func GetWindowPlacement(hwnd uintptr) (WINDOWPLACEMENT, bool)

GetWindowPlacement gets the window placement

Jump to

Keyboard shortcuts

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