auto

package module
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 12 Imported by: 3

README

Automate your Windows machine in Go.

import "github.com/gonutz/auto"

Mouse functions:

// Replace Left with Right or Middle.
err := auto.ClickLeftMouseAt(x, y)
err := auto.ClickLeftMouse()
err := auto.PressLeftMouseAt(x, y)
err := auto.PressLeftMouse()
err := auto.ReleaseLeftMouseAt(x, y)
err := auto.ReleaseLeftMouse()
err := auto.MoveMouseTo(x, y)
err := auto.MoveMouseBy(relativeX, relativeY)
x, y, err := auto.MousePosition()
err := auto.MoveMouseWheelBy(dx, dy)

Keyboard functions:

err := auto.Type("Hello")
err := auto.TypeWithDelay("Hello", 100 * time.Millisecond)
err := auto.TypeKey(auto.KeySpace)
err := auto.PressKey(auto.KeySpace)
err := auto.ReleaseKey(auto.KeySpace)

Screen shot functions:

img, err := auto.CaptureMonitor(Monitor)
img, err := auto.CaptureMonitors([]Monitor)
img, err := auto.CaptureScreen(x, y, width, height int)
img, err := auto.CaptureScreenRect(Rectangle)
img, err := auto.CaptureWindow(Window)
img, err := auto.CaptureWindowContent(Window)

Monitor functions:

allMonitors, err := auto.Monitors()
m, err := auto.PrimaryMonitor()

Window functions:

allWindows, err := auto.Windows()
window, err := auto.ForegroundWindow()
err := window.BringToForeground()
x, y, width, height, err := window.InnerPosition()
err := window.SetInnerPosition(x, y, width, height)
x, y, width, height, err := window.OuterPosition()
err := window.SetOuterPosition(x, y, width, height)
window.Restore()
window.Maximize()
window.Minimize()
window.Hide()
window.Show()
window.Update()

Global Events:

auto.SetOnKeyboardEvent(func(*auto.KeyboardEvent))
auto.SetOnMouseEvent(func(*auto.MouseEvent))
auto.SetOnClipboardChange(func())

Other OS functions:

text, err := auto.ClipboardText()
err := auto.SetClipboardText("Hello")
ShowMessage(caption, message string)

Documentation

Rendered for windows/amd64

Index

Constants

View Source
const (
	LeftMouseDown        MouseEventType = w32.WM_LBUTTONDOWN
	LeftMouseUp                         = w32.WM_LBUTTONUP
	RightMouseDown                      = w32.WM_RBUTTONDOWN
	RightMouseUp                        = w32.WM_RBUTTONUP
	MiddleMouseDown                     = w32.WM_MBUTTONDOWN
	MiddleMouseUp                       = w32.WM_MBUTTONUP
	MouseMove                           = w32.WM_MOUSEMOVE
	MouseWheel                          = w32.WM_MOUSEWHEEL
	MouseWheelHorizontal                = w32.WM_MOUSEHWHEEL
)

These are the available MosueEventTypes. Mouse down and up events are sent when a mouse button is pressed down and released respectively. MouseMove is sent when the mouse moves. MouseWheel is sent when the regular vertical mouse wheel on a desktop mouse is scrolled or when a touch pad is scrolled up or down. MouseWheelHorizontal is sent when a horizontal wheel is scrolled. These typically do not exist on regular desktop mouse devices. This can be triggered with a touch pad scroll from left to right or vice versa.

View Source
const (
	KeyA                  = 'A'
	KeyB                  = 'B'
	KeyC                  = 'C'
	KeyD                  = 'D'
	KeyE                  = 'E'
	KeyF                  = 'F'
	KeyG                  = 'G'
	KeyH                  = 'H'
	KeyI                  = 'I'
	KeyJ                  = 'J'
	KeyK                  = 'K'
	KeyL                  = 'L'
	KeyM                  = 'M'
	KeyN                  = 'N'
	KeyO                  = 'O'
	KeyP                  = 'P'
	KeyQ                  = 'Q'
	KeyR                  = 'R'
	KeyS                  = 'S'
	KeyT                  = 'T'
	KeyU                  = 'U'
	KeyV                  = 'V'
	KeyW                  = 'W'
	KeyX                  = 'X'
	KeyY                  = 'Y'
	KeyZ                  = 'Z'
	Key0                  = '0'
	Key1                  = '1'
	Key2                  = '2'
	Key3                  = '3'
	Key4                  = '4'
	Key5                  = '5'
	Key6                  = '6'
	Key7                  = '7'
	Key8                  = '8'
	Key9                  = '9'
	KeyLeftButton         = w32.VK_LBUTTON
	KeyRightButton        = w32.VK_RBUTTON
	KeyMiddleButton       = w32.VK_MBUTTON
	KeyXButton1           = w32.VK_XBUTTON1
	KeyXButton2           = w32.VK_XBUTTON2
	KeyCancel             = w32.VK_CANCEL
	KeyBackspace          = w32.VK_BACK
	KeyTab                = w32.VK_TAB
	KeyClear              = w32.VK_CLEAR
	KeyEnter              = w32.VK_RETURN
	KeyShift              = w32.VK_SHIFT
	KeyControl            = w32.VK_CONTROL
	KeyAlt                = w32.VK_MENU
	KeyPause              = w32.VK_PAUSE
	KeyCapsLock           = w32.VK_CAPITAL
	KeyImeKana            = w32.VK_KANA
	KeyImeHangul          = w32.VK_HANGUL
	KeyImeOn              = w32.VK_IME_ON
	KeyImeJunja           = w32.VK_JUNJA
	KeyImeFinal           = w32.VK_FINAL
	KeyImeHanja           = w32.VK_HANJA
	KeyImeKanji           = w32.VK_KANJI
	KeyImeOff             = w32.VK_IME_OFF
	KeyEscape             = w32.VK_ESCAPE
	KeyImeConvert         = w32.VK_CONVERT
	KeyImeNonConvert      = w32.VK_NONCONVERT
	KeyImeAccept          = w32.VK_ACCEPT
	KeyImeModeChange      = w32.VK_MODECHANGE
	KeySpace              = w32.VK_SPACE
	KeyPageUp             = w32.VK_PRIOR
	KeyPageDown           = w32.VK_NEXT
	KeyEnd                = w32.VK_END
	KeyHome               = w32.VK_HOME
	KeyLeft               = w32.VK_LEFT
	KeyUp                 = w32.VK_UP
	KeyRight              = w32.VK_RIGHT
	KeyDown               = w32.VK_DOWN
	KeySelect             = w32.VK_SELECT
	KeyPrint              = w32.VK_PRINT
	KeyExecute            = w32.VK_EXECUTE
	KeyPrintScreen        = w32.VK_SNAPSHOT
	KeyInsert             = w32.VK_INSERT
	KeyDelete             = w32.VK_DELETE
	KeyHelp               = w32.VK_HELP
	KeyLeftWin            = w32.VK_LWIN
	KeyRightWin           = w32.VK_RWIN
	KeyApps               = w32.VK_APPS
	KeySleep              = w32.VK_SLEEP
	KeyNum0               = w32.VK_NUMPAD0
	KeyNum1               = w32.VK_NUMPAD1
	KeyNum2               = w32.VK_NUMPAD2
	KeyNum3               = w32.VK_NUMPAD3
	KeyNum4               = w32.VK_NUMPAD4
	KeyNum5               = w32.VK_NUMPAD5
	KeyNum6               = w32.VK_NUMPAD6
	KeyNum7               = w32.VK_NUMPAD7
	KeyNum8               = w32.VK_NUMPAD8
	KeyNum9               = w32.VK_NUMPAD9
	KeyMultiply           = w32.VK_MULTIPLY
	KeyPlus               = w32.VK_ADD
	KeySeparator          = w32.VK_SEPARATOR
	KeyMinus              = w32.VK_SUBTRACT
	KeyDecimal            = w32.VK_DECIMAL
	KeyDivide             = w32.VK_DIVIDE
	KeyF1                 = w32.VK_F1
	KeyF2                 = w32.VK_F2
	KeyF3                 = w32.VK_F3
	KeyF4                 = w32.VK_F4
	KeyF5                 = w32.VK_F5
	KeyF6                 = w32.VK_F6
	KeyF7                 = w32.VK_F7
	KeyF8                 = w32.VK_F8
	KeyF9                 = w32.VK_F9
	KeyF10                = w32.VK_F10
	KeyF11                = w32.VK_F11
	KeyF12                = w32.VK_F12
	KeyF13                = w32.VK_F13
	KeyF14                = w32.VK_F14
	KeyF15                = w32.VK_F15
	KeyF16                = w32.VK_F16
	KeyF17                = w32.VK_F17
	KeyF18                = w32.VK_F18
	KeyF19                = w32.VK_F19
	KeyF20                = w32.VK_F20
	KeyF21                = w32.VK_F21
	KeyF22                = w32.VK_F22
	KeyF23                = w32.VK_F23
	KeyF24                = w32.VK_F24
	KeyNumLock            = w32.VK_NUMLOCK
	KeyScrollLock         = w32.VK_SCROLL
	KeyOemNecEqual        = w32.VK_OEM_NEC_EQUAL
	KeyOemFjJisho         = w32.VK_OEM_FJ_JISHO
	KeyOemFjMasshou       = w32.VK_OEM_FJ_MASSHOU
	KeyOemFjTouroku       = w32.VK_OEM_FJ_TOUROKU
	KeyOemFjLoya          = w32.VK_OEM_FJ_LOYA
	KeyOemFjRoya          = w32.VK_OEM_FJ_ROYA
	KeyLeftShift          = w32.VK_LSHIFT
	KeyRightShift         = w32.VK_RSHIFT
	KeyLeftControl        = w32.VK_LCONTROL
	KeyRightControl       = w32.VK_RCONTROL
	KeyLeftAlt            = w32.VK_LMENU
	KeyRightAlt           = w32.VK_RMENU
	KeyBrowserBack        = w32.VK_BROWSER_BACK
	KeyBrowserForward     = w32.VK_BROWSER_FORWARD
	KeyBrowserRefresh     = w32.VK_BROWSER_REFRESH
	KeyBrowserStop        = w32.VK_BROWSER_STOP
	KeyBrowserSearch      = w32.VK_BROWSER_SEARCH
	KeyBrowserFavorites   = w32.VK_BROWSER_FAVORITES
	KeyBrowserHome        = w32.VK_BROWSER_HOME
	KeyVolumeMute         = w32.VK_VOLUME_MUTE
	KeyVolumeDown         = w32.VK_VOLUME_DOWN
	KeyVolumeUp           = w32.VK_VOLUME_UP
	KeyMediaNextTrack     = w32.VK_MEDIA_NEXT_TRACK
	KeyMediaPreviousTrack = w32.VK_MEDIA_PREV_TRACK
	KeyMediaStop          = w32.VK_MEDIA_STOP
	KeyMediaPlayPause     = w32.VK_MEDIA_PLAY_PAUSE
	KeyLaunchMail         = w32.VK_LAUNCH_MAIL
	KeyLaunchMediaSelect  = w32.VK_LAUNCH_MEDIA_SELECT
	KeyLaunchApp1         = w32.VK_LAUNCH_APP1
	KeyLaunchApp2         = w32.VK_LAUNCH_APP2
	KeyOemPlus            = w32.VK_OEM_PLUS
	KeyOemComma           = w32.VK_OEM_COMMA
	KeyOemMinus           = w32.VK_OEM_MINUS
	KeyOemPeriod          = w32.VK_OEM_PERIOD
	KeyOem1               = w32.VK_OEM_1
	KeyOem2               = w32.VK_OEM_2
	KeyOem3               = w32.VK_OEM_3
	KeyOem4               = w32.VK_OEM_4
	KeyOem5               = w32.VK_OEM_5
	KeyOem6               = w32.VK_OEM_6
	KeyOem7               = w32.VK_OEM_7
	KeyOem8               = w32.VK_OEM_8
	KeyOemAx              = w32.VK_OEM_AX
	KeyOem102             = w32.VK_OEM_102
	KeyIcoHelp            = w32.VK_ICO_HELP
	KeyIco00              = w32.VK_ICO_00
	KeyImeProcessKey      = w32.VK_PROCESSKEY
	KeyIcoClear           = w32.VK_ICO_CLEAR
	KeyUnicodePacket      = w32.VK_PACKET
	KeyOemReset           = w32.VK_OEM_RESET
	KeyOemJump            = w32.VK_OEM_JUMP
	KeyOemPa1             = w32.VK_OEM_PA1
	KeyOemPa2             = w32.VK_OEM_PA2
	KeyOemPa3             = w32.VK_OEM_PA3
	KeyOemWsControl       = w32.VK_OEM_WSCTRL
	KeyOemCuSel           = w32.VK_OEM_CUSEL
	KeyOemAttn            = w32.VK_OEM_ATTN
	KeyOemFinish          = w32.VK_OEM_FINISH
	KeyOemCopy            = w32.VK_OEM_COPY
	KeyOemAuto            = w32.VK_OEM_AUTO
	KeyOemEnlw            = w32.VK_OEM_ENLW
	KeyOemNBackTab        = w32.VK_OEM_BACKTAB
	KeyAttn               = w32.VK_ATTN
	KeyCrSel              = w32.VK_CRSEL
	KeyExSel              = w32.VK_EXSEL
	KeyErEof              = w32.VK_EREOF
	KeyPlay               = w32.VK_PLAY
	KeyZoom               = w32.VK_ZOOM
	KeyNoName             = w32.VK_NONAME
	KeyPa1                = w32.VK_PA1
	KeyOemClear           = w32.VK_OEM_CLEAR
)

Key... constants are keys you can pass to TypeKey, PressKey and ReleaseKey.

Variables

This section is empty.

Functions

func CaptureMonitor

func CaptureMonitor(m Monitor) (image.Image, error)

CaptureMonitor returns a screen shot of the outer boundaries of the given monitor.

func CaptureMonitors

func CaptureMonitors(monitors []Monitor) (image.Image, error)

CaptureMonitors returns a screen shot of the outer hull of all the given monitors. Depending on your operating system settings this may include blank areas which will be transparent in the image. For example, if you have a 1200 pixel high monitor next to a 1080 pixel high monitor, there will a 1200-1080 = 120 pixel high area below the smaller monitor that is transparent.

func CaptureScreen

func CaptureScreen(x, y, width, height int) (image.Image, error)

CaptureScreen returns a screen shot of the given area. The area is given in virtual screen coordinates.

func CaptureScreenRect

func CaptureScreenRect(r Rectangle) (image.Image, error)

CaptureScreenRect is a wrapper for CaptureScreen. It allows you to pass a Monitor's WorkArea to this function instead of unwrapping the Rectangle yourself.

func CaptureWindow

func CaptureWindow(w Window) (image.Image, error)

CaptureWindow returns a screen shot of the outer boundaries of the given window.

func CaptureWindowContent

func CaptureWindowContent(w Window) (image.Image, error)

CaptureWindowContent returns a screen shot of the inner boundaries of the given window.

func ClickLeftMouse

func ClickLeftMouse() error

ClickLeftMouse clicks the left mouse button, i.e. presses and releases it.

func ClickLeftMouseAt

func ClickLeftMouseAt(x, y int) error

ClickLeftMouseAt moves the mouse to screen coordinates x,y and clicks the left mouse button, i.e. presses and releases it.

func ClickMiddleMouse

func ClickMiddleMouse() error

ClickMiddleMouse clicks the middle mouse button, i.e. presses and releases it.

func ClickMiddleMouseAt

func ClickMiddleMouseAt(x, y int) error

ClickMiddleMouseAt moves the mouse to screen coordinates x,y and clicks the middle mouse button, i.e. presses and releases it.

func ClickRightMouse

func ClickRightMouse() error

ClickRightMouse clicks the right mouse button, i.e. presses and releases it.

func ClickRightMouseAt

func ClickRightMouseAt(x, y int) error

ClickRightMouseAt moves the mouse to screen coordinates x,y and clicks the right mouse button, i.e. presses and releases it.

func ClipboardText

func ClipboardText() (string, error)

ClipboardText returns the contents of the clipboard as text. If the clipboard is empty or does not contain text it returns "".

func MousePosition added in v1.1.0

func MousePosition() (x, y int, err error)

MousePosition returns the mouse position in screen coordinates.

func MoveMouseBy

func MoveMouseBy(dx, dy int) error

MoveMouseBy moves the mouse cursor by the given amount of pixels in x and y. Positive x moves the cursor right. Negative x moves the cursor left. Positive y moves the cursor down. Negative y moves the cursor up.

func MoveMouseTo

func MoveMouseTo(x, y int) error

MoveMouseTo move the mouse cursor to the given screen coordinates.

func MoveMouseWheelBy added in v1.3.0

func MoveMouseWheelBy(dx, dy float64) error

MoveMouseWheelBy rotates the mouse wheel, vertically and/or horizontally. dy is the vertical rotation, dy = 1 means one tick forward, away from the user. dy = -1 means one tick backward, towards the user. dx is the horizontal rotation. dx = 1 means one tick to the right, dx = -1 means one tick to the left.

func PressKey

func PressKey(key uint16) error

PressKey presses the given key on the keyboard. You can pass key codes defined in this package, named Key...

func PressLeftMouse

func PressLeftMouse() error

PressLeftMouse presses the left mouse button down. Call ReleaseLeftMouse or ReleaseLeftMouseAt to release the button.

func PressLeftMouseAt

func PressLeftMouseAt(x, y int) error

PressLeftMouseAt moves the mouse to screen coordinates x,y and presses the left mouse button down. Call ReleaseLeftMouse or ReleaseLeftMouseAt to release the button.

func PressMiddleMouse

func PressMiddleMouse() error

PressMiddleMouse presses the middle mouse button down. Call ReleaseMiddleMouse or ReleaseMiddleMouseAt to release the button.

func PressMiddleMouseAt

func PressMiddleMouseAt(x, y int) error

PressMiddleMouseAt moves the mouse to screen coordinates x,y and presses the middle mouse button down. Call ReleaseMiddleMouse or ReleaseMiddleMouseAt to release the button.

func PressRightMouse

func PressRightMouse() error

PressRightMouse presses the right mouse button down. Call ReleaseRightMouse or ReleaseRightMouseAt to release the button.

func PressRightMouseAt

func PressRightMouseAt(x, y int) error

PressRightMouseAt moves the mouse to screen coordinates x,y and presses the right mouse button down. Call ReleaseRightMouse or ReleaseRightMouseAt to release the button.

func ReleaseKey

func ReleaseKey(key uint16) error

ReleaseKey releases the given key on the keyboard. You can pass key codes defined in this package, named Key...

func ReleaseLeftMouse

func ReleaseLeftMouse() error

ReleaseLeftMouse releases the left mouse button. You probably want to press it before, using PressLeftMouseAt or PressLeftMouse.

func ReleaseLeftMouseAt

func ReleaseLeftMouseAt(x, y int) error

ReleaseLeftMouseAt moves the mouse to screen coordinates x,y and releases the left mouse button. You probably want to press it before, using PressLeftMouseAt or PressLeftMouse.

func ReleaseMiddleMouse

func ReleaseMiddleMouse() error

ReleaseMiddleMouse releases the middle mouse button. You probably want to press it before, using PressMiddleMouseAt or PressMiddleMouse.

func ReleaseMiddleMouseAt

func ReleaseMiddleMouseAt(x, y int) error

ReleaseMiddleMouseAt moves the mouse to screen coordinates x,y and releases the middle mouse button. You probably want to press it before, using PressMiddleMouseAt or PressMiddleMouse.

func ReleaseRightMouse

func ReleaseRightMouse() error

ReleaseRightMouse releases the right mouse button. You probably want to press it before, using PressRightMouseAt or PressRightMouse.

func ReleaseRightMouseAt

func ReleaseRightMouseAt(x, y int) error

ReleaseRightMouseAt moves the mouse to screen coordinates x,y and releases the right mouse button. You probably want to press it before, using PressRightMouseAt or PressRightMouse.

func SetClipboardText

func SetClipboardText(text string) error

SetClipboardText sets the contents of the clipboard to the given string.

func SetOnClipboardChange added in v1.5.0

func SetOnClipboardChange(f func())

SetOnClipboardChange sets a callback that is called every time the content of the clipboard changes.

func SetOnKeyboardEvent added in v1.4.0

func SetOnKeyboardEvent(f func(*KeyboardEvent))

SetOnKeyboardEvent sets a callback that is called every time a keyboard event happens, i.e. a key is pressed or released. Set it to nil to stop listening to keyboard events.

func SetOnMouseEvent added in v1.4.0

func SetOnMouseEvent(f func(*MouseEvent))

SetOnMouseEvent sets a callback that is called every time a mouse event happens, i.e. a button is pressed or released, the mouse moves or the mouse wheel is rotated. Set it to nil to stop listening to mouse events.

func ShowMessage added in v1.6.0

func ShowMessage(caption, message string)

func Type

func Type(s string) error

Type will write the given text using Alt+Numpad numbers. It will sleep the smallest, non-0 delay between two letters.

func TypeKey

func TypeKey(key uint16) error

TypeKey presses and releases the given key on the keyboard. The value must be a virtual keycode like 'A', '1' or VK_RETURN (you can use the constants in github.com/gonutz/w32 VK_...).

func TypeWithDelay

func TypeWithDelay(s string, delay time.Duration) error

TypeWithDelay will write the given text using Alt+Numpad numbers. It will sleep the given delay between two letters.

Types

type KeyboardEvent added in v1.4.0

type KeyboardEvent struct {
	Key      uint16
	Down     bool
	Injected bool
	// contains filtered or unexported fields
}

KeyboardEvent is given to the callback passed to SetOnKeyboardEvent. Every time a keyboard event is triggered by either the user or programmatically (e.g. by this library), a KeyboardEvent is sent. Key is the virtual key code, see the Key... constants defined in this library. Down indicates whether the key is presed down (true) or released (false). Injected is true if the key event was generated programmatically.

func (*KeyboardEvent) Cancel added in v1.4.0

func (e *KeyboardEvent) Cancel()

Cancel stops the event from being handled further. That means the currently focussed window will not receive the event.

type Monitor

type Monitor struct {
	// Rectangle is the outer boundary of the monitor, in virtual screen
	// coordinates. All monitors share this virtual coordinate system. In your
	// operating system settings you can freely move monitors around in this
	// coordinate system to represent the real world layout of your monitors.
	// For example, you might put two monitors side by side or on top of each
	// other.
	Rectangle
	// WorkArea is the monitor area that is not covered by the task bar.
	WorkArea Rectangle
	// Primary is true if this is the current default/primary monitor.
	Primary bool
}

Monitor is a single monitor connected to your computer.

func Monitors

func Monitors() ([]Monitor, error)

Monitors returns all monitors currently connected to the computer.

func PrimaryMonitor

func PrimaryMonitor() (Monitor, error)

PrimaryMonitor returns the current default/primary monitor.

type MouseEvent added in v1.4.0

type MouseEvent struct {
	Type     MouseEventType
	X        int
	Y        int
	Wheel    float64
	Injected bool
	// contains filtered or unexported fields
}

MouseEvent is given to the callback passed to SetOnMouseEvent. Every time a mouse event is triggered by either the user or programmatically (e.g. by this library), a MouseEvent is sent. Type is the concrete event type (button, move or wheel event). X and Y are the screen coordinates in monitor space. These can be negative, e.g. if you place your second monitor left of the primary monitor (and tell Windows via its settings). Wheel is the amount of ticks the mouse wheel has rotated. This is only set for events MouseWheel and MouseWheelHorizontal, otherwise it is 0. Injected is true if the key event was generated programmatically.

func (*MouseEvent) Cancel added in v1.4.0

func (e *MouseEvent) Cancel()

Cancel stops the event from being handled further. That means the currently focussed window will not receive the event.

type MouseEventType added in v1.4.0

type MouseEventType int

MouseEventType is the concrete type of a MouseEvent.

type Rectangle

type Rectangle struct {
	// X is the left-most pixel.
	X int
	// Y is the top-most pixel.
	Y int
	// Width is the width in pixels.
	Width int
	// Height is the height in pixels.
	Height int
}

Rectangle is used to desribe monitor and window boundaries.

type Window

type Window struct {
	// Rectangle is the window's outer boundaries in virtual screen coordinates.
	Rectangle
	// Content is the window's inner boundaries in virtual screen coordinates.
	Content Rectangle
	// Visible is true if the window is a visual window. For background windows
	// Visible is false.
	Visible bool
	// Title is the text currently displayed in the window header.
	Title string
	// ClassName is the name of the class of this window. Multiple windows can
	// have the same class.
	ClassName string
	// Maximized is true if the window is currently maximized.
	Maximized bool
	// Minimized is true if the window is currently minimized.
	Minimized bool
	// Handle is the operating specific window handle.
	Handle w32.HWND
}

Window is a window currently open on you system.

func ForegroundWindow

func ForegroundWindow() (Window, error)

ForegroundWindow returns the currently active window. If no window is active, ForegroundWindow returns an error.

func Windows

func Windows() ([]Window, error)

Windows returns a list of all currently active windows.

func (*Window) BringToForeground

func (w *Window) BringToForeground() error

BringToForeground tries to bring the given window to the front.

func (*Window) Hide

func (w *Window) Hide()

Hide hides the window. Call ShowWindow to show it again.

func (*Window) InnerPosition added in v1.2.0

func (w *Window) InnerPosition() (x, y, width, height int, err error)

InnerPosition reutrns the boundaries of the window content, i.e. without window borders, in screen coordinates.

func (*Window) Maximize

func (w *Window) Maximize()

Maximize maximizes the given window.

func (*Window) Minimize

func (w *Window) Minimize()

Minimize minimizes the given window.

func (*Window) OuterPosition added in v1.2.0

func (w *Window) OuterPosition() (x, y, width, height int, err error)

OuterPosition returns the bounaries of the window border, in screen coordinates.

func (*Window) Restore

func (w *Window) Restore()

Restore unminimizes a minimized window and unmaximizes a maximized window.

func (*Window) SetInnerPosition added in v1.2.0

func (w *Window) SetInnerPosition(x, y, width, height int) error

SetInnerPosition sets the boundaries of the window border.

Note that if the window is currently maximized, you might want to Restore() it before calling SetInnerPosition to un-maximize it.

Note that if the window is currently maximized, you might want to Restore() it before calling SetInnerPosition to bring it back up. This might now restore to a maximized state, thus you probably want to call Restore() it twice in that case.

func (*Window) SetOuterPosition added in v1.2.0

func (w *Window) SetOuterPosition(x, y, width, height int) error

SetOuterPosition sets the boundaries of the window border.

Note that if the window is currently maximized, you might want to Restore() it before calling SetOuterPosition to un-maximize it.

Note that if the window is currently maximized, you might want to Restore() it before calling SetOuterPosition to bring it back up. This might now restore to a maximized state, thus you probably want to call Restore() it twice in that case.

func (*Window) Show

func (w *Window) Show()

Show shows the given window. Call this to show a window that was hidden with Hide.

func (*Window) Update

func (w *Window) Update()

Update updates the state of the window, all fields are queried from the OS again. If the state or size of a window changes, Update will poll these changes.

Directories

Path Synopsis
samples

Jump to

Keyboard shortcuts

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