winscreencap

package module
v0.0.0-...-718109d Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: MIT Imports: 8 Imported by: 0

README

winscreencap

Golang Windows Screen Capture Library

Install

go get github.com/chixm/winscreencap

Choose Window and Capture Image

How to save the window named "game" as an png image screenshot.png

    hwnd, err := winscreencap.FindWindowByName(`game`)
	if err != nil {
		t.Error(err)
		return
	}

	img, err := winscreencap.CaptureWindow(hwnd)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	file, err := os.Create("screenshot.png")
	if err != nil {
		fmt.Println("Error:", err)
		return
	}
	defer file.Close()

	err = png.Encode(file, img)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

Documentation

Index

Constants

View Source
const (
	WithWindowFrame = Options(1 << iota) // 1 Include Windows Frame in png image
	NoAlphaFix                           // 2 Do not automatically fix even alpha value is zero,
)
View Source
const (
	WDA_NONE               = 0x00000000
	WDA_MONITOR            = 0x00000001
	WDA_EXCLUDEFROMCAPTURE = 0x00000011
)

Variables

This section is empty.

Functions

func CaptureWindow

func CaptureWindow(hwnd win.HWND, options ...Options) (image.Image, error)

Capture all the window

func EnumWindows

func EnumWindows(enumFunc WNDENUMPROC, lParam uintptr) error

func FindWindowByName

func FindWindowByName(windowName string) (win.HWND, error)

func GetActiveWindow

func GetActiveWindow() (win.HWND, error)

func GetDesktopWindow

func GetDesktopWindow() (win.HWND, error)

for desktop image capture

func GetWindowDisplayAffinity

func GetWindowDisplayAffinity(hwnd win.HWND) (uint32, error)

Some Windows are Disabled to Capture

func SetLogger

func SetLogger(l Logger)

SetLogger if original log output needed

Types

type Logger

type Logger interface {
	Infoln(args ...any)
	Errorln(args ...any)
}

type Options

type Options uint32

CaptureOptions

type WNDENUMPROC

type WNDENUMPROC func(hwnd win.HWND, lParam uintptr) uintptr

type WindowInfo

type WindowInfo struct {
	Hwnd  win.HWND
	Title string
}

func GetWindowList

func GetWindowList() []*WindowInfo

get all visible window list

Jump to

Keyboard shortcuts

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