Technical Documentation: go-vgo/robotgo
ℹ️ Provenance: Multi-Tier Ingestion · CodeWiki Reference
Overview (`README.md`)
Robotgo
English | 简体中文 | 繁體中文 | 日本語 | 한국어 | Français | Deutsch | Español | Русский | Português
Golang Desktop Automation, auto test and AI Computer Use.
Control the mouse, keyboard, read the screen, process, Window Handle, image and bitmap and global event listener.
RobotGo supports Mac, Windows, and Linux; and robotgo supports arm64 and x86-amd64.
I build Codg now, Easy code and work AI agent system: auto, asynchronous, concurrency, efficiently and High accuracy
RobotGo-Pro get the JavaScript, Python, Lua and others version, tech supports, new features and newest robotgo version ("no open-source version now").
Contents
- Docs
- Donate
- Binding
- Requirements
- Cgo-free Builds
- Installation
- Update
- Examples
- Type Conversion and keys
- Cross-Compiling
- Authors
- Plans
- License
Docs
Donate
Donors and sponsors, or others, Contact: [email protected]
Binding
ADB, packaging android adb and ios wda, robotgo compatible API.
Requirements
Go 1.26+ (see go.mod) and one backend:
- Default (Cgo):
CGO_ENABLED=1, a C compiler and the platform libraries below. - Pure Go (tested): no C toolchain; see Cgo-free Builds.
Both need the feature-specific dependencies
for the features you use.
Default Cgo setup
macOS
Go and the Xcode Command Line Tools (Clang):
brew install go
xcode-select --installPermissions (Cgo and pure Go): in System Settings > Privacy & Security,
grant the app or terminal Accessibility (input) and Screen Recording
(capture).
Windows
winget install GoLang.GoPlus one C toolchain. LLVM-MinGW:
winget install MartinStorsjo.LLVM-MinGW.UCRT
$env:CC = "clang"winget install BrechtSanders.WinLibs.POSIX.UCRT
$env:CC = "gcc"The toolchain's bin (e.g. C:\mingw64\bin) must be on PATH and matchGOARCH. Any other Cgo-compatible compiler, such as a manual
MinGW-w64 install, also works.
Bitmap ships libpng for MinGW-w64 only;
with another toolchain, build libpng yourself.
Linux (X11)
Build: GCC, libc headers, X11/XTest headers. Runtime: an X server with XTEST
and DISPLAY set. For native Wayland, see Cgo-free Builds.
Ubuntu / Debian:
# Go (Snap if the distro package is too old)
sudo snap install go --classic
# or: sudo apt install golang
# Core (Cgo): compiler, libc, X11, XTest
sudo apt install gcc libc6-dev libx11-dev xorg-dev libxtst-dev
# Clipboard (X11)
sudo apt install xsel xclip
# Bitmap: libpng
sudo apt install libpng++-dev
# GoHook: XCB, XKB
sudo apt install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev libxkbcommon-devFedora:
# Core (Cgo): compiler, libc, X11, XTest
sudo dnf install gcc glibc-devel libX11-devel libXtst-devel
# Clipboard (X11)
sudo dnf install xsel xclip
# Bitmap: libpng
sudo dnf install libpng-devel
# GoHook: XKB (Fedora < 34: xorg-x11-xkb-utils-devel instead of xkbcomp-devel)
sudo dnf install libxkbcommon-devel libxkbcommon-x11-devel xkbcomp-develFeature-specific dependencies
Needed on top of the core setup, only for the features you use:
Linux clipboard (Cgo and pure Go):
xcliporxselon X11;wl-clipboardon Wayland:shsudo apt install wl-clipboard # Ubuntu / Debian sudo dnf install wl-clipboard # FedoraBitmap: libpng headers.
GoHook: XCB/XKB headers on Linux.
Bitmap and GoHook are separate Cgo packages; a pure-Go RobotGo backend does not
remove their C requirements.
Cgo-free Builds
Tested pure-Go backends build and cross-compile with CGO_ENABLED=0
(no GCC, MinGW, Xcode or X11 headers). Same import path and API; a build tag
selects the backend — CGO_ENABLED=0 alone selects nothing.
Target GOOS |
Build tag | Package | Runtime requirements |
|---|---|---|---|
windows |
win |
win | Win32 only, no extra runtime |
darwin |
mac |
darwin | System frameworks and privacy permissions |
linux |
x11 |
x11 | X server with XTEST, DISPLAY set |
linux |
wayland |
wayland | wlroots compositor, see Wayland |
linux |
libei |
libei | RemoteDesktop portal (GNOME/KDE), see libei |
purego is a shortcut: mac on macOS, win on Windows, wayland on
Linux. Add x11 or libei to override on Linux (-tags "purego,x11").
Use one backend tag matching GOOS; combinations such as x11,libei fail
to compile (purego plus one Linux override is the only exception).
Build commands
# Current OS
CGO_ENABLED=0 go build -tags purego .
# Cross-compile
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags win .
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -tags mac .
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags x11 .
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags wayland .
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags libei .PowerShell: $env:CGO_ENABLED = "0"; go build -tags purego .
Build the module root (.) or your own package, not ./...: examples/ and
some subpackages need Cgo-only APIs.
Limitations
The runtime requirements above still apply. Cgo-only APIs such asCaptureScreen / FreeBitmap do not exist; use CaptureImg. Unsupported
operations return ErrNotSupported (or an empty result).
mac: window management (GetTitle,GetBounds,ActivePid,ActiveName,MinWindow,MaxWindow,CloseWindow) uses Accessibility
and needs the Accessibility permission;MaxWindowtoggles native full
screen andGetClientequalsGetBounds.wayland,libei: Wayland has no protocol for the global cursor
position.Location()reads the real cursor from Hyprland (IPC socket) and
KDE Plasma (KWin script over D-Bus) when that query succeeds;waylandalso
needs every output to share one scale ratio (differently scaled or rotated
outputs fall back). Otherwise, and elsewhere (GNOME, Sway, other wlroots
compositors), it returns the last position injected by RobotGo, not the
physical cursor. Clipboard needswl-clipboard.
Wayland
A wlroots compositor (Sway, Hyprland, Wayfire, ...) with WAYLAND_DISPLAY andXDG_RUNTIME_DIR set, exposing:
| Feature | Protocol global |
|---|---|
| Mouse control | zwlr_virtual_pointer_manager_v1 |
| Keyboard control | zwp_virtual_keyboard_manager_v1 |
| Screen capture | zwlr_screencopy_manager_v1 |
| Window management | zwlr_foreign_toplevel_manager_v1 |
GNOME and KDE do not provide these protocols; use libei there.
libei (GNOME / KDE)
Input goes through the xdg-desktop-portal RemoteDesktop D-Bus interface:
needs a session bus, xdg-desktop-portal and a backend implementing it
(xdg-desktop-portal-gnome, -kde or -wlr). The first run shows a consent
dialog; the restore token is cached under $XDG_STATE_HOME/robotgo.
Absolute motion uses a linked ScreenCast stream (default); setlibei.LinkScreenCast = false for relative motion only. Screen capture and
window management report ErrNotSupported.
Installation
go get github.com/go-vgo/robotgoimport "github.com/go-vgo/robotgo"png.h: No such file or directory with Bitmap: see its libpng requirements and
issues/47.
Update
go get -u github.com/go-vgo/robotgoNote go1.10.x C file compilation cache problem, golang #24355.go mod vendor problem, golang #26366.
[Examples](https://github.com/go-vgo/robotgo/blob/master/examples)
[Mouse](https://github.com/go-vgo/robotgo/blob/master/examples/mouse/main.go)
/* Detailed source-code truncated for AI context efficiency. */[Keyboard](https://github.com/go-vgo/robotgo/blob/master/examples/key/main.go)
package main
import (
"errors"
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
robotgo.Type("Hello World")
robotgo.Type("だんしゃり", 0, 1)
// robotgo.Type("テストする")
robotgo.Type("Hi, Seattle space needle, Golden gate bridge, One world trade center.")
robotgo.Type("Hi galaxy, hi stars, hi MT.Rainier, hi sea. こんにちは世界.")
robotgo.Sleep(1)
// ustr := uint32(robotgo.CharCodeAt("Test", 0))
// robotgo.UnicodeType(ustr)
robotgo.KeySleep = 100
robotgo.KeyTap("enter")
// robotgo.Type("en")
robotgo.KeyTap("i", "alt", "cmd")
arr := []string{"alt", "cmd"}
robotgo.KeyTap("i", arr)
robotgo.MilliSleep(100)
robotgo.KeyToggle("a")
robotgo.KeyToggle("a", "up")
robotgo.WriteAll("Test")
text, err := robotgo.ReadAll()
if err == nil {
fmt.Println(text)
}
// Unknown key names return an error instead of pressing a wrong key
if err := robotgo.KeyTap("notakey"); err != nil {
fmt.Println("robotgo.KeyTap error:", err)
}
// TypeStr returns the first typing error, Type only returns the count
if err := robotgo.TypeStr("Hello, 世界"); err != nil {
fmt.Println("robotgo.TypeStr error:", err)
}
// Hold a modifier, then always release it and check both errors
if err := robotgo.KeyDown("shift"); err == nil {
err = errors.Join(robotgo.KeyTap("a"), robotgo.KeyUp("shift"))
if err != nil {
fmt.Println("shift + a error:", err)
}
}
}[Screen](https://github.com/go-vgo/robotgo/blob/master/examples/screen/main.go)
package main
import (
"fmt"
"strconv"
"github.com/go-vgo/robotgo"
"github.com/vcaesar/imgo"
)
func main() {
x, y := robotgo.Location()
fmt.Println("pos: ", x, y)
color := robotgo.GetPixelColor(100, 200)
fmt.Println("color---- ", color)
sx, sy := robotgo.GetScreenSize()
fmt.Println("get screen size: ", sx, sy)
bit := robotgo.CaptureScreen(10, 10, 30, 30)
defer robotgo.FreeBitmap(bit)
img := robotgo.ToImage(bit)
imgo.Save("test.png", img)
num := robotgo.DisplaysNum()
for i := 0; i < num; i++ {
robotgo.DisplayID = i
img1, _ := robotgo.CaptureImg()
path1 := "save_" + strconv.Itoa(i)
robotgo.Save(img1, path1+".png")
robotgo.SaveJpeg(img1, path1+".jpeg", 50)
img2, _ := robotgo.CaptureImg(10, 10, 20, 20)
robotgo.Save(img2, "test_"+strconv.Itoa(i)+".png")
x, y, w, h := robotgo.GetDisplayBounds(i)
img3, err := robotgo.CaptureImg(x, y, w, h)
fmt.Println("Capture error: ", err)
robotgo.Save(img3, path1+"_1.png")
}
}[Bitmap](https://github.com/vcaesar/bitmap/blob/main/examples/main.go)
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
"github.com/vcaesar/bitmap"
)
func main() {
bit := robotgo.CaptureScreen(10, 20, 30, 40)
// use `defer robotgo.FreeBitmap(bit)` to free the bitmap
defer robotgo.FreeBitmap(bit)
fmt.Println("bitmap...", bit)
img := robotgo.ToImage(bit)
// robotgo.SavePng(img, "test_1.png")
robotgo.Save(img, "test_1.png")
bit2 := robotgo.ToCBitmap(robotgo.ImgToBitmap(img))
fx, fy := bitmap.Find(bit2)
fmt.Println("FindBitmap------ ", fx, fy)
robotgo.Move(fx, fy)
arr := bitmap.FindAll(bit2)
fmt.Println("Find all bitmap: ", arr)
fx, fy = bitmap.Find(bit)
fmt.Println("FindBitmap------ ", fx, fy)
bitmap.Save(bit, "test.png")
}[OpenCV](https://github.com/vcaesar/gcv)
package main
import (
"fmt"
"math/rand"
"github.com/go-vgo/robotgo"
"github.com/vcaesar/gcv"
"github.com/vcaesar/bitmap"
)
func main() {
opencv()
}
func opencv() {
name := "test.png"
name1 := "test_001.png"
robotgo.SaveCapture(name1, 10, 10, 30, 30)
robotgo.SaveCapture(name)
fmt.Print("gcv find image: ")
fmt.Println(gcv.FindImgFile(name1, name))
fmt.Println(gcv.FindAllImgFile(name1, name))
bit := bitmap.Open(name1)
defer robotgo.FreeBitmap(bit)
fmt.Print("find bitmap: ")
fmt.Println(bitmap.Find(bit))
// bit0 := robotgo.CaptureScreen()
// img := robotgo.ToImage(bit0)
// bit1 := robotgo.CaptureScreen(10, 10, 30, 30)
// img1 := robotgo.ToImage(bit1)
// defer robotgo.FreeBitmapArr(bit0, bit1)
img, _ := robotgo.CaptureImg()
img1, _ := robotgo.CaptureImg(10, 10, 30, 30)
fmt.Print("gcv find image: ")
fmt.Println(gcv.FindImg(img1, img))
fmt.Println()
res := gcv.FindAllImg(img1, img)
fmt.Println(res[0].TopLeft.Y, res[0].Rects.TopLeft.X, res)
x, y := res[0].TopLeft.X, res[0].TopLeft.Y
robotgo.Move(x, y-rand.Intn(5))
robotgo.MilliSleep(100)
robotgo.Click()
res = gcv.FindAll(img1, img) // use find template and sift
fmt.Println("find all: ", res)
res1 := gcv.Find(img1, img)
fmt.Println("find: ", res1)
img2, _, _ := robotgo.DecodeImg("test_001.png")
x, y = gcv.FindX(img2, img)
fmt.Println(x, y)
}[Event](https://github.com/robotn/gohook/blob/master/examples/main.go)
package main
import (
"fmt"
// "github.com/go-vgo/robotgo"
hook "github.com/robotn/gohook"
)
func main() {
add()
low()
event()
}
func add() {
fmt.Println("--- Please press ctrl + shift + q to stop hook ---")
hook.Register(hook.KeyDown, []string{"q", "ctrl", "shift"}, func(e hook.Event) {
fmt.Println("ctrl-shift-q")
hook.End()
})
fmt.Println("--- Please press w---")
hook.Register(hook.KeyDown, []string{"w"}, func(e hook.Event) {
fmt.Println("w")
})
s := hook.Start()
<-hook.Process(s)
}
func low() {
evChan := hook.Start()
defer hook.End()
for ev := range evChan {
fmt.Println("hook: ", ev)
}
}
func event() {
ok := hook.AddEvents("q", "ctrl", "shift")
if ok {
fmt.Println("add events...")
}
keve := hook.AddEvent("k")
if keve {
fmt.Println("you press... ", "k")
}
mleft := hook.AddEvent("mleft")
if mleft {
fmt.Println("you press... ", "mouse left button")
}
}[Window](https://github.com/go-vgo/robotgo/blob/master/examples/window/main.go)
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
fpid, err := robotgo.FindIds("Google")
if err == nil {
fmt.Println("pids... ", fpid)
if len(fpid) > 0 {
robotgo.Type("Hi galaxy!", fpid[0])
robotgo.KeyTap("a", fpid[0], "cmd")
robotgo.KeyToggle("a", fpid[0])
robotgo.KeyToggle("a", fpid[0], "up")
robotgo.ActivePid(fpid[0])
robotgo.Kill(fpid[0])
}
}
robotgo.ActiveName("chrome")
isExist, err := robotgo.PidExists(100)
if err == nil && isExist {
fmt.Println("pid exists is", isExist)
robotgo.Kill(100)
}
abool := robotgo.Alert("test", "robotgo")
if abool {
fmt.Println("ok@@@ ", "ok")
}
title := robotgo.GetTitle()
fmt.Println("title@@@ ", title)
}Authors
Plans
- Better multiscreen support
- Update Window Handle
Contributors
- See contributors page for full list of contributors.
- See Contribution Guidelines.
License
Robotgo is primarily distributed under the terms of "the Apache License (Version 2.0)", with portions covered by various BSD-like licenses.
See LICENSE-APACHE, LICENSE.
Overview (`clipboard/README.md`)
This directory based on clipboard.
Clipboard for Go
Provide copying and pasting to the Clipboard for Go.
Build:
$ go get github.com/atotto/clipboardPlatforms:
- OSX
- Windows 7 (probably work on other Windows)
- Linux, Unix, the first available tool is used:
- Wayland:
wl-clipboard(wl-copy/wl-paste), whenWAYLAND_DISPLAYis set - X11:
xcliporxsel - Android Termux:
termux-clipboard-get/termux-clipboard-set(Termux:API add-on) - WSL: the Windows clipboard via
clip.exe/powershell.exe - tmux: the tmux paste buffer, when running inside tmux (
TMUXis set)
- Wayland:
- Plan 9 (
/dev/snarf)
clipboard.Primary = true selects the primary selection on Wayland and X11,
other tools fall back to the clipboard.
Document:
Notes:
- Text string only
- UTF-8 text encoding only (no conversion)
TODO:
- Clipboard watcher(?)
Commands:
paste shell command:
$ go get github.com/atotto/clipboard/cmd/gopaste
$ # example:
$ gopaste > document.txtcopy shell command:
$ go get github.com/atotto/clipboard/cmd/gocopy
$ # example:
$ cat document.txt | gocopyOverview (`docs/README.md`)
Docs
Documents are not necessarily updated synchronously, slower than godoc, please see examples and godoc.
Overview (`examples/README.md`)
Robotgo examples
Install:
go get -u github.com/go-vgo/robotgo[Examples:](https://github.com/go-vgo/robotgo/blob/master/examples)
[Mouse](https://github.com/go-vgo/robotgo/blob/master/examples/mouse/main.go)
package main
import (
"github.com/go-vgo/robotgo"
)
func main() {
// robotgo.ScrollMouse(10, "up")
robotgo.Scroll(0, 10)
robotgo.MouseClick("left", true)
robotgo.MoveSmooth(100, 200, 1.0, 100.0)
}[Keyboard](https://github.com/go-vgo/robotgo/blob/master/examples/key/main.go)
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
robotgo.TypeStr("Hello World")
// robotgo.TypeStr("だんしゃり")
robotgo.TypeStr("だんしゃり")
// ustr := uint32(robotgo.CharCodeAt("だんしゃり", 0))
// robotgo.UnicodeType(ustr)
robotgo.KeyTap("enter")
robotgo.TypeStr("en")
robotgo.KeyTap("i", "alt", "command")
arr := []string{"alt", "command"}
robotgo.KeyTap("i", arr)
robotgo.WriteAll("Test")
text, err := robotgo.ReadAll()
if err == nil {
fmt.Println(text)
}
}[Screen](https://github.com/go-vgo/robotgo/blob/master/examples/screen/main.go)
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
x, y := robotgo.Location()
fmt.Println("pos:", x, y)
color := robotgo.GetPixelColor(100, 200)
fmt.Println("color----", color)
}[Bitmap](https://github.com/go-vgo/robotgo/blob/master/examples/bitmap/main.go)
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
bitmap := robotgo.CaptureScreen(10, 20, 30, 40)
// use `defer robotgo.FreeBitmap(bit)` to free the bitmap
defer robotgo.FreeBitmap(bitmap)
fmt.Println("...", bitmap)
fx, fy := robotgo.FindBitmap(bitmap)
fmt.Println("FindBitmap------", fx, fy)
robotgo.SaveBitmap(bitmap, "test.png")
}[Event](https://github.com/go-vgo/robotgo/blob/master/examples/event/main.go)
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
keve := robotgo.AddEvent("k")
if keve {
fmt.Println("you press...", "k")
}
mleft := robotgo.AddEvent("mleft")
if mleft {
fmt.Println("you press...", "mouse left button")
}
}[Window](https://github.com/go-vgo/robotgo/blob/master/examples/window/main.go)
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
fpid, err := robotgo.FindIds("Google")
if err == nil {
fmt.Println("pids...", fpid)
if len(fpid) > 0 {
robotgo.ActivePID(fpid[0])
robotgo.Kill(fpid[0])
}
}
robotgo.ActiveName("chrome")
isExist, err := robotgo.PidExists(100)
if err == nil && isExist {
fmt.Println("pid exists is", isExist)
robotgo.Kill(100)
}
abool := robotgo.ShowAlert("test", "robotgo")
if abool == 0 {
fmt.Println("ok@@@", "ok")
}
title := robotgo.GetTitle()
fmt.Println("title@@@", title)
}CHANGELOG (`docs/CHANGELOG.md`)
CHANGELOG
Unreleased
Fixed
- [FIX] libei backend:
Move/MoveSmoothwere no-ops andLocationalways returned (0, 0) under-tags libei(#783). The RemoteDesktop session now links a ScreenCast monitor stream soNotifyPointerMotionAbsoluteworks,Movefalls back to relative motion when no stream is available,MoveSmoothtargets an absolute position,Locationreports the last injected position, andGetScreenSize/GetScreenRectreturn the stream geometry. Addedlibei.LinkScreenCastto opt out of the stream. - [FIX] libei backend:
Locationis now a pure query — it no longer opens a RemoteDesktop session (polling it re-prompted the consent dialog whenever the session was denied or closed) and keeps reporting the last injected position after the portal closes the session (#783). - [FIX] Cgo Linux:
num_equalusedXK_equal(main-row=) instead ofXK_KP_Equal;right_shiftis accepted as a modifier name by the Cgo and every pure-Go backend. - [FIX] Cgo:
MoveSmooth/DragSmoothcould stop 1px short of the target (the loop exited once the remaining distance was ≤ 1, soLocation()right afterMoveSmooth(100, 100)returned(101, 100)); the loop now runs until the pointer is on the target.robotgo_test.gois untagged and runs the Move → Location / key / clipboard / capture checks against the Cgo and every pure-Go backend (skipping cleanly when headless); Cgo-only bitmap APIs moved torobot_cgo_test.go. Added fake-pointer Move/Location tests for the wayland backend. - [FIX] Cgo:
GetPixelColorsegfaulted andToImage(CaptureScreen())panicked when the screen could not be grabbed (macOS without the Screen Recording permission); they now return black / an empty image.KeyTap("no_such_key")returns an error instead of pressing keycode 0. - [ADD] Pure-Go backends:
SysScale/ScaleF/Scaledare wired for every backend (go test robot_info_test.gofailed to build under-tags purego). macOS reports the Retina backing scale, Windows the DPI scale, X11 the physical DPI orXft.dpi/ 96 (like the Cgo backend), Wayland thewl_output.scalefactor of the selected output; libei reports 1 (the portal only exposes logical geometry). Wayland/X11GetScaleSizemultiply by the scale like the Cgo backend. - [FIX] wayland backend:
Locationreturns the last injected position instead of a (0, 0) stub. - [FIX] wayland backend: serialize all go-wayland context access (event dispatch vs. request/proxy creation raced on the unsynchronized object table);
CaptureImgno longer hangs forever when the connection dies (5s timeout), handles XBGR/ABGR shm formats and they_invertflag; the virtual keyboard now sends themodifiersrequest so shift/ctrl/alt combos work and uses a sealed memfd keymap with the full evdev keycode set (F13-F24, media keys, ...);Scrollsendsaxis_source+axis_discrete;Movemaps onto the whole output layout;MinWindow/MaxWindowact on the active toplevel; closed toplevel handles are destroyed; malformed toplevel events can no longer panic the dispatch goroutine. - [FIX] libei backend:
Movewithout a ScreenCast stream parks the pointer in the corner first instead of being a no-op; points in monitor gaps are clamped;Typemaps\n/\t/\b/Esc to function keysyms;KeyTap("A")implies shift; sessions closed by the portal are re-established;GetScaleSize(displayId)honours the display. - [FIX] darwin (purego) backend: events are created from a HID-system-state source like the Cgo backend; punctuation, shifted symbols (
!,{, ...) and numpad keys resolve;ScaleF/GetScaleSizereport the Retina backing scale;GetScreenRect(displayId)returns that display's bounds. - [FIX] win (pure-Go) backend: key events carry the hardware scan code (raw-input consumers ignored them); numpad and media keys resolve;
ScaleF/GetScaleSizereport the DPI scale;GetScreenRectfollows the Cgo backend's virtual-screen rule. - [FIX] All pure-Go backends:
Scroll/ScrollDiruse the same sign convention as the Cgo backend (positive y = up, positive x = left); the darwin/win/wayland/libei ports previously inverted it. - [NEW] Cgo and every pure-Go backend:
Move,Drag,DragSmooth,MoveClick,MoveRelative,MoveSmoothRelative,MovesClick,Scroll,ScrollDir,ScrollSmooth,ScrollRelative,UnicodeType,TypeStr,TypeDelayandTypeStrDelaynow returnerror(previously silent no-ops on failure).ScrollDirrejects an unknown or non-string direction instead of doing nothing / panicking;DragSmoothalways releases the button even when the move fails (and rejects wrong-typed args instead of panicking with the button held);Typekeeps returning the typed count and stops at the first character that fails.MoveSmoothRelative/MovesClickreturn the exportedErrSmoothMove. - [FIX] Cgo
Type/UnicodeType: runes above the BMP (emoji) are sent as a UTF-16 surrogate pair on macOS/Windows instead of being truncated to 16 bits; on LinuxToUCspells them as XlibU1F600soXStringToKeysymresolves them, andinput_utfreports an unknown keysym / missing keyboard mapping / rejected XTEST event instead of returning success. Windows: typing into a pid whose window is not found returnsERROR_INVALID_WINDOW_HANDLE(previously posted to the caller's own queue and "succeeded");NotPidis honoured byType; an input rejected by UIPI/secure desktop is reported as such instead ofwinapi error #-1. macOS: no longerCFRelease(NULL)when the event source can not be created. - [FIX] win (pure-Go) backend: after a partial
KeyTap/KeyTogglepress failure only the keys that were actually pressed are released, so keys held by the user are not keyed up.
RobotGo v0.100.0, MT. Baker; Enhancement bitmap and image, add arm support...
Add
[NEW] add more image function support
[NEW] add ImgToBitmap(), ToImg(), FindEveryBitmap(), FindEveryColor(), Svae(), Read(), SaveJpeg() and other function support
[NEW] add func ToImage: convert C.MMBitmapRef to standard image.Image
[NEW] add ToImage examples code
[NEW] add more image function and update go mod
[NEW] add find every color function
[NEW] add free and find all point function
[NEW] update find bitmap and color
[NEW] add byte to image function
[NEW] add more image convert function
[NEW] add mac os M1 support
[NEW] add windows arm support
[NEW] add more key toggle and press function
[NEW] add ToRGBA() function support
[NEW] add ImgToBitmap and RGBAToBitmap support
[NEW] Update and move image function to img.go
[NEW] add more img to bitmap examples code and Update file name
Update
[NEW] Update README.md and CHANGELOG.md
[NEW] add macOS to .travis.yml
[NEW] update go mod pkg
[NEW] Update hook examples link to newest
[NEW] update dockerfile and appveyor to go1.14.4
[NEW] Update README.md, add more examples
[NEW] move hook and event to gohook
[NEW] move cbitmap and bitmap-bytes to bitmap dir
[NEW] update some name
[NEW] update dockerfile and appveyor.yml
[NEW] update clipboard code
[NEW] update hook code and more API
[NEW] optimize code and update version
[NEW] add paste string err return and optimize code
[NEW] update go.yml and travis.yml to go1.15
[NEW] Update Ubuntu apt-get to apt
[NEW] update go version and key code
[NEW] update test code and go mod
[NEW] Update README.md and test code
[NEW] update parameter name and version
[NEW] update dockerfile and appveyor.yml
[NEW] update error return and print
[NEW] update ShowAlert optimize return code
[NEW] add more test and update go mod
[NEW] compatible with 32-bit platforms
[NEW] add more bitmap examples
[NEW] update point structure to public
[NEW] add more examples
[NEW] update examples and version
[NEW] Update clipboard example code
[NEW] Update README.md Section ####Other to windows (#348) …
[NEW] Update png.h path
[NEW] Update go mod
[NEW] Update circle.yml and travis.yml
[NEW] Remove unless example code and update circle.yml
[NEW] Removed drop api example code and Update README.md
[NEW] Update go mod and xx.yml
[NEW] Update README.md and example
[NEW] add more bitmap examples code
[NEW] Update go mod and Update README.md
[NEW] gofmt to 1.17 build tag
[NEW] Update bitmap examples code
[NEW] Update version and keycode
[NEW] Update docs remove drop API
Fixed
[FIX] Update go mod and fixed #290
[FIX] Update gohook to v0.30.2 fixed bug
[FIX] Fixed Mouse buttons reversed type
[FIX] Fixed returns "Invalid key code specified." if specified character is not v… … add keyCodeForCharFallBack
[FIX] This fixes the disappearing backslash issue #351
[FIX] Export ToUC function and update test code
[FIX] Fixes #258: char* arrays in C not being copied correctly
[FIX] Fixed Linux TypeStr() function double quote
[FIX] update free bitmap fixed #333
[FIX] update gops to v0.20.0 fixed bug and other mod pkg
[FIX] update gohook fixed warning
RobotGo v0.90.0, MT. Rainier
Add
add gohook modern and concurrent API
add new gohook examples, thks for cauefcr
Support for multiple screens
add getMousePos() multiple screens support
add move smooth multiple screens support
add all platform system scale support
add get screen size test code
add screen and bitmap multiple screens support
add int32_t types support
update keycode type use uint16 with gohook, not type convert
add ToBitmapBytes func (#204)
gohook: sched_yield support for non-POSIX windows gcc
add gops test code support
add Process() function test code
add more gops test code
add more win32 function export
add get mouse color function
add uint32 to Chex function support
add key_Toggles() c function
add keyTap and keyToggle "...string" parameters support, Fixed #209
add robotgo simple test code
add Is64Bit() c and go function
add process FindPath() function
add keycode "delete" support and fixed "\" error
add more keycode support, "up, down, left, right"...
export hook keycode and add godoc
use robotn fork xgb and update go mod
add hook example to robotgo examples
update gohook and tt mod file
add more and update test code
add drag smooth function support and examples
add ShowAlert() test support
update keypress rand sleep [reduce] and update code style, update c delay default value to 0
add mouse toggle return and add more test
add SetDelay function code and update other code
add scaled function code
add go opencv file
add readme.md file
add move mouse and move smooth relative code
add move mouse and move smooth relative examples
add more test code and update go tt mod
add more bitmap test code
add SaveImg function code
add drop function hint print support
add more key test code
add more test code
add paste string test code
add xvfb run codecov test
add keycode test support
add FindPath example code
add KeyTap() args[2] delay support
add find bitmap nil args support
add find color nil args support
add drag and move mouse multiple screens support
add drag mouse test code
Use CGDisplayBounds not CGDisplayPixelsWide, optimize get mac display size …
Update TypeStr function, add type delay and speed support
update PasteStr function code return error
Update
Update robot info test code and Add go.yml test support
use while not for match special key map
remove unless x11 special key and sort
update go mod pkg
update mod vendor
remove vendor and update .gitignore
update and fmt config.yml, add Linux go test support
update Linux CI support x11 test
move hook to hook.go
update appveyor and test code
update version and code style
update move mouse smooth test code
update clipboard code and add test code
update test code and add codecov support
update show alert test code
update keycode.go
update window examples code
update test code remove windows alert test
move gops code to ps.go
update version
update unix get title type
gofmt go code and update code style
add ToBitmapBytes examples code
update example code, fixed golint warning
update bitmap example code
Update CHANGELOG.md
update code style
update godoc
update keytap code and code style
update Bitmap struct delete fuzzy api
update key examples code
add bitmap from string clear api
update go mod vendor
update go mod pkg not proxy
update bitmap example code
update test code fixed appveyor CI
update test code fixed equal error
update hook godoc
update event example code
update godoc and code style
update key example code
Update example README.md
update and tidy go mod
update code remove duplicate code and update godoc
update xgb getXid log
update GetBounds x11 error log
update cgo code and version
update TypeString function code [Drop]
update key example code
Update TypeStr function, optimize x11 type string
Update TypeStrDelay function, remove unused code
update code fixed x11 type sleep
Update key example code
use gops to simplify code
update key examples code
update bitmap examples code
update colorpicker and findcolor example code
update bitmap example code
update robotgo test code, add more test
Update README.md
rename type names make clearer
update types.h code and fixed bug
remove unused code fixed x11 build error
update robot info test code and appveyor
Update README.md, Add more CI badge
update gohook pkg and robot info test code
Update linux upper code, add more special key support
Create go.yml
Update go.yml
add more test and update go.yml
Update dockerfile to go1.13.5
update dockerfile and appveyor.yml
Update dockerfile and appveyor.yml to go1.14.3
remove Travis go1.11.x
update appveyor and dockerfile to go1.13.1
update dockerfile, go.yml and appveyor.yml to go1.14
update travis.yml to go1.14.x and remove go1.13.x
Update and fmt appveyor.ymlu
update dockerfile and appveyor to go1.12.5
update appveyor and dockerfile to go1.12.6
add CI go1.13 support
update config.yml
update and fmt travis.yml
Update Travis remove go1.12.x
Update issue and pull request template
Fix
Update to utf-code function Fixed #189
Update x11 keypress upper code Fixed #243
type conversion needed in addMouse (#201)
update hook, Fixed #202 fatal error: concurrent map writes
add key Kind Fixed #203
optimize get title code, Fixed #165 and typo
Fixed gohook#3 mouse is_drag error on x11
Fixed #213 AddEvents() can't listen correctly multiple times
update clipboard error hand Fixed #212
Update go.mod fixing issue "invalid pseudo-version: does not match version …
update keyboard example code, #238
update go mod file Fixed #239
update gops and other mod files fixed bug
RobotGo v0.80.0, Sierra Nevada
Sierra Nevada
Add
[NEW] Add asynchronous event support
[NEW] Add multiple keypress event listener support
[NEW] Add hook start and end func
[NEW] Add AddEvents, AddMouse, AddMousePos hook function
[NEW] Add mul() scale func and optimize code
[NEW] Refactor AddEvent() func and add keycode.go, update example
[NEW] Add mouse map keycode
[NEW] Add android null file
[NEW] Add AddEvent "center" support
[NEW] Update README.md, Add binding link
[NEW] Format README.md and docs markdown
[NEW] Update bitmap_save return code
[NEW] Optimize code not defer and remove useless code
[NEW] Update code style and godoc
[NEW] Update go mod vendor
[NEW] Add more event examples
[NEW] add AddEvents, AddMouse, AddMousePos examples code
Update
- [NEW] Update event example code add print hint
- [NEW] Update godoc
- [NEW] Update CHANGELOG.md
- [NEW] Update .gitignore
- [NEW] Update code style and examples
- [NEW] Update pkg to newest
- [NEW] Update CI add go1.12.x support
- [NEW] Move GetText() func code
Fix
- [FIX] Add AddEvents func, Fixed #98, #61, #69...
- [FIX] Add asynchronous event support, Fixed #196, #89...
- [FIX] add AddMouse func, Fixed #138
- [FIX] Update _Ctype_char to C.char, Fixed go1.12 build error #191
- [FIX] Update hook, Fixed #195 warning and json break bug
- [FIX] Fixed color picker, Update README.md and docs
See Commits for more details, after Jan 7.
RobotGo v0.70.0, Caloris Montes
Caloris Montes
Add
[NEW] Update keyboard use sendInput not keybd_event
[NEW] Update mouse use sendInput not mouse_event
[NEW] Add drag mouse other button support
[NEW] Add more numpad key support
[NEW] Add numpad key and escape abbreviation support
[NEW] Add new window10 zoom ratio
[NEW] Add linux numpad key support
[NEW] Add key "insert, printscreen" mac support
[NEW] Add check mouse button func
[NEW] Add keyTap run error return support and update godoc
[NEW] Optimize and clearer keytap code
[NEW] Optimize and clean keyToggle code
[NEW] Update dockerfile clean image
[NEW] Add color picker and getMousePos() example
[NEW] Use go mod not dep, add go.mod remove dep files
[NEW] Add GetColors func return string
[NEW] Optimize defer code
[NEW] Add more godoc
[NEW] Add add key "ctrl", "cmd" [ abbreviation ] support
[NEW] Add add key "capslock", "numpad_lock" support
[NEW] Add left and right "Ctrl, Shift, Alt, command" key support
[NEW] Update check key flags support "cmd" and "ctrl"
[NEW] Update key docs
[NEW] Add millisleep func and update godoc
[NEW] Add AddEvent() key "cmd" support
[NEW] Update key example code
[NEW] Update README.md, add Note go1.10.x issue
[NEW] Update keytap and toggle return "" and code style
Update
[NEW] Update issue template more obvious
[NEW] Update godoc
[NEW] Update CHANGELOG.md
[NEW] Update .gitignore
[NEW] Update code style and examples
[NEW] Update pkg to newest
[NEW] Add more scale example
[NEW] Add drag mouse example
[NEW] Update key docs and clear file name
[NEW] Remove old useless code
[NEW] Update README.md
[NEW] Update CI add go1.11.4 version
Fix
- [FIX] Fixed bitmapClick() parameter bug
- [FIX] Fixed some README.md typo
- [FIX] Update scale example code close #153
- [FIX] Update code style and fixed #endif error
See Commits for more details, after Otc 8.
RobotGo v0.60.0, Mount Olympus: Mytikas
Add
[NEW] Add GetBounds func support (add get_client and get_frame C_func)
[NEW] Add GetXId and GetXidFromPid func
[NEW] Refactoring GetTitle() func allow by pid
[NEW] Refactoring CloseWindow() allow by pid
[NEW] Add SetHandPid() and GetHandPid() func support
[NEW] Add FindCBitmap func support
[NEW] Refactoring bitmap example code
[NEW] Refactoring key example code
[NEW] Refactoring window example code
[NEW] Add an cbitmap example [#169]
[NEW] Refactoring screen and event example code
[NEW] Refactoring mouse example code
[NEW] Add more godoc
[NEW] Add getTitle example by pid
[NEW] Add close window example by pid
[NEW] Add getBounds example
[NEW] Split func and remove dep more clean
[NEW] Simplify SaveCapture code
[NEW] Update and merged get_pixel_color remove duplicate code
[NEW] Update README.md, add Note go1.10.x
Update
[NEW] Update issue template more obvious
[NEW] Move public mdata to pub
[NEW] Update godoc
[NEW] Update CHANGELOG.md
[NEW] Move some pub method to pub.h and rename some c_func
[NEW] Update code style and name style ( key, window and other )
[NEW] Update robotgo unix export getXidFromPid func
[NEW] Update set handle return use bool
[NEW] Update code style and move scale to win_sys.h
[NEW] Update example add more lang
[NEW] Update pkg to newest
[NEW] Remove duplicate code and old useless code
[NEW] Update and clean README.md
[NEW] Update CI add go1.11.x version
[NEW] Update scroll godoc and clearer parameter name
[NEW] Update hint and code style
[NEW] Update FindIds doc and only set name once in loop
Fix
- [FIX] Update type_string fixed #155, fixed window missing some character
- [FIX] Fixed GetWindowText return address of local variable and not use ternary operator ( GetTittle )
- [FIX] Update README.md Fixed Release badge
See Commits for more details, after Aug 8.
RobotGo v0.50.0, The Appalachian Mountains
Add
- [NEW] Add simple ocr support
- [NEW] Add max and min window api and win32.h file
- [NEW] Automatic free internal bitmap and add bitmapStr example
- [NEW] Update findBitmap and findColor default tolerance 0.5 to 0.01, [improve find accuracy and time]
- [NEW] Add more Window example
- [NEW] Add cross compile docs
- [NEW] Add free bitmap and tolerance godoc
- [NEW] Add GetForegroundWindow and FindWindow func support
- [NEW] Add bitmap to CBitmap func, Add ToCBitmap example to examples
- [NEW] Add get Scale and GetScaleSize func, get primary display DPI scale factor fix #129, #135
Add Custom DPI Scaling support,
Add scale default value,
Add scale example
Update
- [NEW] Update README.md [add freeBitmap example]
- [NEW] Optimize findColor and uniform API with findBitmap
- [NEW] Update godoc, CI and README.md
- [NEW] Update CHANGELOG.md
- [NEW] Update examples [add freeBitmap and update findColor]
- [NEW] Optimize bitmap code, optimize args and not try [many methods]
- [NEW] Update getPid type to int32
- [NEW] Update var and other code style, fix non-standard code
Update code and update some name - [NEW] Update pkg to newest
- [NEW] Remove duplicate code and old useless code
- [NEW] Update mouse click and fix moveClick and movesClick args
- [NEW] Update code style use if not try
- [NEW] Update clipboard example
- [NEW] Update typestr use return not else
- [NEW] Update mouse toggle, keytap and savebitmap func args
- [NEW] Update examples remove duplicate code
- [NEW] Update bitmap and other examples
- [NEW] Simplify linux dependency installation commands
- [NEW] Update issue_template.md
-[NEW] Update pull_request_template.md - [NEW] Move govendor to dep
- [NEW] Update robotgo ci to 1.10.3
Fix
- [FIX] Update active pid to fix #140, fixed linux activePid
- [FIX] Fixed findBitmap and findPic memory leak
- [FIX] Add getPxColor destroyMMBitmap fix memory leak
- [FIX] Fix float args not float32
- [FIX] Fix windows clipboard memory leak
- [FIX] Update macos .a downgrade to 10.10 just warning not exit [fix #102, #128, #134]
- [FIX] use 10.10 to compile .a verifyed multi os
- [FIX] Fix #145 not assert
- [FIX] Fix some warning use supplemental code
See Commits for more details, after Apr 30.
RobotGo v0.49.0, Olympus Mons
Add
- [NEW] Add get image size func
- [NEW] Add linux type string utf-8 support
- [NEW] Add scroll mouse support x, y
- [NEW] Add AddEvent() "esc" support fix #105
- [NEW] Add AddEvent "space" fix #110
- [NEW] Add clipboard choose primary mode on unix
- [NEW] Add move smooth return
- [NEW] Add more bitmap func and examples
- [NEW] Add MicroSleep func
- [NEW] Add find image by path
Update
- [NEW] Update KeyToggle code
- [NEW] Update activePid allow Windows via hwnd
- [NEW] Update godoc and README.md
- [NEW] Update CHANGELOG.md
- [NEW] Update Kill() parameter and examples
- [NEW] Update examples and remove useless function
- [NEW] Update appveyor, circle and dockerfile
- [NEW] Update code style
- [NEW] Update and optimize func
- [NEW] Update travis support go 1.10
- [NEW] Update CI (use custom go image) and add func internalFindBitmap
- [NEW] Update godoc and deprecated GetBHandle
- [NEW] Optimize code func args and name
Fix
- [FIX] Fix mac input method keytap not work
- [FIX] Fix clipboard golint
- [FIX] Update move smooth fix #96 (set mouse smooth speed)
- [FIX] Fix Getportion param to go type
- [FIX] Fix XFlush wait for events flushing
See Commits for more details, after Jan 25.
RobotGo v0.48.0, Ben Nevis
Add
- [NEW] Add active window by name func ActiveName
- [NEW] Add type string utf-8 support
Add func CharCodeAt, UnicodeType, PasteStr and update TypeStr, TypeString
- [NEW] Add count of bitmap func CountBitmap
- [NEW] Add func SaveCapture and examples
- [NEW] Add time sleep func Sleep
- [NEW] Add more key listen
- [NEW] Add func PointInBounds and examples
- [NEW] Add func GetPxColor return C.MMRGBHex
- [NEW] Add FindColorCS param tolerance
- [NEW] Add func ToBitmap and examples
- [NEW] Add CBitmap type and examples
- [NEW] Add more examples
- [NEW] Add func ToMMBitmapRef
- [NEW] Add func BitmapClick and MovesClick
- [NEW] Add func ToMMRGBHex convert color hex
- [NEW] Add func count bitmap color and CountColorCS
- [NEW] Add more color processing and conversion
Add func ToMMRGBHex, U32ToHex, U8ToHex, PadHex, HexToRgb, RgbToHex and examples
- [NEW] Add func tochar bitmap and gostring and fmt code
Update
- [NEW] Remove robot and examples
- [NEW] Update vendor and appveyor.yml
- [NEW] Update keyboard code
- [NEW] Update godoc
- [NEW] Update CHANGELOG.md
- [NEW] Change TostringBitmap return string
- [NEW] Update C language code and other naming
- [NEW] Update code and code style
- [NEW] Update move mouse smooth
Fix
- [FIX] Fix mac set active and active by pid
- [FIX] Fix windows active by pid #101
- [FIX] Fix FindColor param tolerance
- [FIX] Fix find bitmap float args
- [FIX] Fix some range error
- [FIX] Update doc fix #97
- [FIX] Update README.md fix link error
See Commits for more details, after Dec 13.
RobotGo v0.47.0, Mount Cook
Add
- [NEW] Add windows 32bit and 64bit dependency
- [NEW] Add macOs dependency
- [NEW] Add pkg to vendor
Solve the problem of dependence, remove zlib/libpng dependencies
- [NEW] Add FindColorCS(x, y, w, h int, color CHex), CHex type and examples #84
- [NEW] Add kill the process
- [NEW] Add public event and update code
- [NEW] Add Windows 32bit and 64bit Appveyor CI
Update
- [NEW] Update png io
- [NEW] Update cgo link
- [NEW] Update .gitignore
- [NEW] Update README.md and godoc
- [NEW] Update CHANGELOG.md
- [NEW] Update circle to 2.0, add robotgo Dockerfile custom image
- [NEW] Update and fmt C code
- [NEW] Update GetTitle default value "null" to ""
Fix
- [FIX] Fix FindColor inconvenient parameters
- [FIX] Fix installation requirements #72
- [FIX] Fix GetTitle
return address of local variablein the higher gcc version. #81
See Commits for more details, after Nov 10.
RobotGo v0.46.6, Pyrenees Mountains: Aneto Peak
RobotGo v0.46.0, Pyrenees Mountains
Add
- [NEW] Add ActivePID
- [NEW] Add FindBit
- [NEW] Add robot branch, where there is no zlib and libpng dependency
Update
- [NEW] Update README.md
- [NEW] Update FindIds
- [NEW] Update examples
- [NEW] Update vendor
- [NEW] Update godoc and docs
- [NEW] Update and fix bitmap
Fix
- [FIX] Fix MoveMouseSmooth args
- [FIX] Fix name err
- [FIX] Fix FindBitmap
RobotGo v0.45.0, Mount Qomolangma
Add
- [NEW] Add Process
- [NEW] Add TypeStr
- [NEW] Add DeepCopyBit
- [NEW] Add CopyBitpb
- [NEW] Add ReadBitmap
- [NEW] Add vendor.json
- [NEW] Add ReadAll: clipboard
- [NEW] Add WriteAll: clipboard
- [NEW] Add Pids : get the all process id
- [NEW] Add FindName: find the process name by the process id
- [NEW] Add FindNames: find the all process name
- [NEW] Add PidExists: determine whether the process exists
- [NEW] Add FindIds: find the process id by the process name
- [NEW] Add FreeBitmap and Update docs
Update
- [NEW] Update docs
- [NEW] Update test
- [NEW] Update godoc
- [NEW] Update CHANGELOG.md
- [NEW] Update .gitignore
- [NEW] Update examples and docs
- [NEW] Update examples link
- [NEW] Update README.md and clipboard
Fix
- [FIX] Fix release key
- [FIX] Fix godoc error
RobotGo v0.44.0, Mount Kailash
Add
- Add CHANGELOG.md
- Format some code
- Add fedora dependencies
Update
- Update test
- Update keys.md
- Update and Split example
- Update godoc and docs
- Update and Cleanup README.md
- Update CONTRIBUTING.md and issue_template.md
Fix
- Fix typesetting and MD error
- Fix fedora dependencies #55
- Fix doc.md and README.md
Install (`docs/install.md`)
CGO CrossCompiling
Windows64 to windows32
SET CGO_ENABLED=1
SET GOARCH=386
go build main.goOther to windows
Install Requirements (Ubuntu):
sudo apt install gcc-multilib
sudo apt install gcc-mingw-w64
# fix err: zlib.h: No such file or directory, Just used by bitmap.
sudo apt install libz-mingw-w64-devBuild the binary:
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -x ./// CC=mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\gcc.exe
// CXX=mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\g++.exeSome discussions and questions, please see issues/228, issues/143.
Keys (`docs/keys.md`)
Type Conversion
| type conversion | func | |
|---|---|---|
| * | robotgo.Bitmap -> robotgo.CBitmap | robotgo.ToCBitmap() |
| robotgo.Bitmap -> *image.RGBA | robotgo.ToRGBAGo() | |
| * | robotgo.CBitmap -> C.MMBitmapRef | robotgo.ToMMBitmapRef() |
| robotgo.CBitmap -> robotgo.Bitmap | robotgo.ToBitmap() | |
| robotgo.CBitmap -> image.Image | robotgo.ToImage() | |
| robotgo.CBitmap -> *image.RGBA | robotgo.ToRGBA() | |
| * | C.MMBitmapRef -> robotgo.CBitmap | robotgo.CBitmap() |
| * | image.Image -> robotgo.Bitmap | robotgo.ImgToBitmap() |
| image.Image -> robotgo.CBitmap | robotgo.ImgToCBitmap() | |
| image.Image -> []byte | robotgo.ToByteImg() | |
| image.Image -> string | robotgo.ToStringImg() | |
| * | *image.RGBA -> robotgo.Bitmap | robotgo.RGBAToBitmap() |
| * | []byte -> image.Image | robotgo.ByteToImg() |
| []byte-> robotgo.CBitmap | robotgo.ByteToCBitmap() | |
| []byte -> string | string() | |
| * | string -> image.Image | robotgo.StrToImg() |
| string -> byte | []byte() |
Keys
/* Detailed source-code truncated for AI context efficiency. */Archive README Zh (`docs/archive/README_zh.md`)
Robotgo
!!! Warning: this page not updated !!!
Golang 跨平台自动化系统,控制键盘、鼠标、位图、图像、读取屏幕,进程、窗口句柄以及全局事件监听
RobotGo 支持 Mac, Windows, and Linux(X11).
提 Issues 请到 Github, 便于统一管理和即时更新; REDAME_zh.md 已废弃, 不再更新
Contents
- Docs
- Binding
- Requirements
- Installation
- Update
- Examples
- Cross-Compiling
- Authors
- Plans
- Donate
- Contributors
- License
Docs
Binding:
Robotn, binding JavaScript and other, support more language.
Requirements:
环境要求:
在安装 RobotGo 之前, 请确保 Golang、GCC 被正确安装
ALL:
Golang
GCCFor Mac OS X:
Xcode Command Line Tools (And Privacy setting: #277 )
xcode-select --installFor Windows:
MinGW-w64 (推荐使用)
Or the other GCC (But you should compile the "libpng" with yourself.
Or you can removed the bitmap.go.)For everything else (Linux 等其他系统):
GCC,
libpng(bitmap)
X11 with the XTest extension (also known as the Xtst library)
事件:
xcb, xkb, libxkbcommon
Clipboard:
xsel xclipUbuntu:
sudo apt install gcc libc6-dev
sudo apt install libx11-dev xorg-dev libxtst-dev libpng++-dev
sudo apt install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev libxkbcommon-dev
sudo apt install xsel xclipFedora:
sudo dnf install libXtst-devel libxkbcommon-devel libxkbcommon-x11-devel xorg-x11-xkb-utils-devel
sudo dnf install libpng-devel
sudo dnf install xsel xclipInstallation:
With Go module support (Go 1.11+), just import:
import "github.com/go-vgo/robotgo"Otherwise, to install the robotgo package, run the command:
go get github.com/go-vgo/robotgopng.h: No such file or directory? Please see issues/47.
Update:
go get -u github.com/go-vgo/robotgo注意 go1.10.x C 文件编译缓存问题, golang #24355.go mod vendor problem, golang #26366.
[Examples:](https://github.com/go-vgo/robotgo/blob/master/examples)
[鼠标](https://github.com/go-vgo/robotgo/blob/master/examples/mouse/main.go)
package main
import (
"github.com/go-vgo/robotgo"
)
func main() {
// robotgo.ScrollMouse(10, "up")
robotgo.Scroll(0, -10)
robotgo.Scroll(100, 0)
robotgo.MilliSleep(100)
// robotgo.ScrollRelative(10, -100)
robotgo.ScrollSmooth(-10, 6)
robotgo.MouseSleep = 100
robotgo.Move(10, 20)
robotgo.MoveRelative(0, -10)
robotgo.Drag(10, 10)
robotgo.Click("left", true)
robotgo.MoveSmooth(100, 200, 1.0, 10.0)
robotgo.Toggle("left")
robotgo.Toggle("left", "up")
}[键盘](https://github.com/go-vgo/robotgo/blob/master/examples/key/main.go)
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
robotgo.TypeStr("Hello World. Winter is coming!")
robotgo.TypeStr("だんしゃり", 1.0)
// robotgo.TypeStr("テストする")
robotgo.TypeStr("Hi galaxy. こんにちは世界.")
robotgo.Sleep(1)
// ustr := uint32(robotgo.CharCodeAt("テストする", 0))
// robotgo.UnicodeType(ustr)
robotgo.KeySleep = 100
robotgo.KeyTap("enter")
// robotgo.TypeStr("en")
robotgo.KeyTap("i", "alt", "command")
arr := []string{"alt", "command"}
robotgo.KeyTap("i", arr)
robotgo.MilliSleep(100)
robotgo.KeyToggle("a")
robotgo.KeyToggle("a", "up")
robotgo.WriteAll("テストする")
text, err := robotgo.ReadAll()
if err == nil {
fmt.Println(text)
}
}[屏幕](https://github.com/go-vgo/robotgo/blob/master/examples/screen/main.go)
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
"github.com/vcaesar/imgo"
)
func main() {
x, y := robotgo.GetMousePos()
fmt.Println("pos: ", x, y)
color := robotgo.GetPixelColor(100, 200)
fmt.Println("color----", color)
sx, sy := robotgo.GetScreenSize()
fmt.Println("get screen size: ", sx, sy)
bit := robotgo.CaptureScreen(10, 10, 30, 30)
defer robotgo.FreeBitmap(bit)
robotgo.SaveBitmap(bit, "test_1.png")
img := robotgo.ToImage(bit)
imgo.Save("test.png", img)
}[位图](https://github.com/go-vgo/robotgo/blob/master/examples/bitmap/main.go)
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
bitmap := robotgo.CaptureScreen(10, 20, 30, 40)
// use `defer robotgo.FreeBitmap(bit)` to free the bitmap
defer robotgo.FreeBitmap(bitmap)
fmt.Println("bitmap...", bitmap)
img := robotgo.ToImage(bitmap)
robotgo.SavePng(img, "test_1.png")
bit2 := robotgo.ToCBitmap(robotgo.ImgToBitmap(img))
fx, fy := robotgo.FindBitmap(bit2)
fmt.Println("FindBitmap------ ", fx, fy)
robotgo.Move(fx, fy)
arr := robotgo.FindAllBitmap(bit2)
fmt.Println("Find all bitmap: ", arr)
robotgo.SaveBitmap(bitmap, "test.png")
fx, fy = robotgo.FindBitmap(bitmap)
fmt.Println("FindBitmap------", fx, fy)
robotgo.SaveBitmap(bitmap, "test.png")
}[OpenCV](https://github.com/vcaesar/gcv)
package main
import (
"fmt"
"math/rand"
"github.com/go-vgo/robotgo"
"github.com/vcaesar/gcv"
)
func main() {
opencv()
}
func opencv() {
name := "test.png"
name1 := "test_001.png"
robotgo.SaveCapture(name1, 10, 10, 30, 30)
robotgo.SaveCapture(name)
fmt.Print("gcv find image: ")
fmt.Println(gcv.FindImgFile(name1, name))
fmt.Println(gcv.FindAllImgFile(name1, name))
bit := robotgo.OpenBitmap(name1)
defer robotgo.FindBitmap(bit)
fmt.Print("find bitmap: ")
fmt.Println(robotgo.FindBitmap(bit))
// bit0 := robotgo.CaptureScreen()
// img := robotgo.ToImage(bit0)
// bit1 := robotgo.CaptureScreen(10, 10, 30, 30)
// img1 := robotgo.ToImage(bit1)
// defer robotgo.FreeBitmapArr(bit0, bit1)
img := robotgo.CaptureImg()
img1 := robotgo.CaptureImg(10, 10, 30, 30)
fmt.Print("gcv find image: ")
fmt.Println(gcv.FindImg(img1, img))
fmt.Println()
res := gcv.FindAllImg(img1, img)
fmt.Println(res[0].TopLeft.Y, res[0].Rects.TopLeft.X, res)
x, y := res[0].TopLeft.X, res[0].TopLeft.Y
robotgo.Move(x, y-rand.Intn(5))
robotgo.MilliSleep(100)
robotgo.Click()
res = gcv.FindAll(img1, img) // use find template and sift
fmt.Println("find all: ", res)
res1 := gcv.Find(img1, img)
fmt.Println("find: ", res1)
img2, _, _ := robotgo.DecodeImg("test_001.png")
x, y = gcv.FindX(img2, img)
fmt.Println(x, y)
}[事件](https://github.com/go-vgo/robotgo/blob/master/examples/gohook/main.go)
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
hook "github.com/robotn/gohook"
)
func main() {
add()
low()
event()
}
func add() {
fmt.Println("--- Please press ctrl + shift + q to stop hook ---")
robotgo.EventHook(hook.KeyDown, []string{"q", "ctrl", "shift"}, func(e hook.Event) {
fmt.Println("ctrl-shift-q")
robotgo.EventEnd()
})
fmt.Println("--- Please press w---")
robotgo.EventHook(hook.KeyDown, []string{"w"}, func(e hook.Event) {
fmt.Println("w")
})
s := robotgo.EventStart()
<-robotgo.EventProcess(s)
}
func low() {
evChan := hook.Start()
defer hook.End()
for ev := range evChan {
fmt.Println("hook: ", ev)
}
}
func event() {
ok := robotgo.AddEvents("q", "ctrl", "shift")
if ok {
fmt.Println("add events...")
}
keve := robotgo.AddEvent("k")
if keve {
fmt.Println("you press... ", "k")
}
mleft := robotgo.AddEvent("mleft")
if mleft {
fmt.Println("you press... ", "mouse left button")
}
}[窗口句柄](https://github.com/go-vgo/robotgo/blob/master/examples/window/main.go)
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
fpid, err := robotgo.FindIds("Google")
if err == nil {
fmt.Println("pids...", fpid)
if len(fpid) > 0 {
robotgo.ActivePID(fpid[0])
robotgo.Kill(fpid[0])
}
}
robotgo.ActiveName("chrome")
isExist, err := robotgo.PidExists(100)
if err == nil && isExist {
fmt.Println("pid exists is", isExist)
robotgo.Kill(100)
}
abool := robotgo.Alert("test", "robotgo")
if abool {
fmt.Println("ok@@@ ", "ok")
}
title := robotgo.GetTitle()
fmt.Println("title@@@ ", title)
}CrossCompiling
Windows64 to windows32
SET CGO_ENABLED=1
SET GOARCH=386
go build main.goOther to windows
Install Requirements (Ubuntu):
sudo apt install gcc-multilib
sudo apt install gcc-mingw-w64
sudo apt install libz-mingw-w64-devBuild the binary:
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -x ./// CC=mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\gcc.exe
// CXX=mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\g++.exeAuthors
Plans
- 更新 Find an image on screen, read pixels from an image
- 更新 Window Handle
- 尝试支持 Android, 也许支持 IOS
Contributors
- See contributors page for full list of contributors.
- See Contribution Guidelines.
License
Robotgo is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.
See LICENSE-APACHE, LICENSE-MIT.
Archive Doc (`docs/archive/doc.md`)
Methods:
[GetVersion](#GetVersion)
[Keyboard](#Keyboard)
[Keys](https://github.com/go-vgo/robotgo/blob/master/docs/keys.md)
[SetKeyDelay](#SetKeyDelay)
[KeyTap](#KeyTap)
[KeyToggle](#KeyToggle)
[TypeStr](#TypeStr)
[TypeStrDelay](#TypeStrDelay)
[WriteAll](#WriteAll)
[ReadAll](#ReadAll)
[Mouse](#Mouse)
[SetMouseDelay](#SetMouseDelay)
[MoveMouse](#MoveMouse)
[Move](#MoveMouse) (Equivalent to MoveMouse)
[MoveMouseSmooth](#MoveMouseSmooth)
[MoveSmooth](#MoveMouseSmooth) (Equivalent to MoveMouseSmooth)
[MouseClick](#MouseClick)
[Click](#MouseClick) (Equivalent to MouseClick)
[MoveClick](#MoveClick)
[MouseToggle](#MouseToggle)
[DragMouse](#DragMouse)
[Drag](#DragMouse) (Equivalent to DragMouse)
[GetMousePos](#GetMousePos)
[ScrollMouse](#ScrollMouse)
[Screen](#Screen)
[GetPixelColor](#GetPixelColor)
[GetScreenSize](#GetScreenSize)
[CaptureScreen](#CaptureScreen)
[GetXDisplayName(Linux)](#GetXDisplayName)
[SetXDisplayName(Linux)](#SetXDisplayName)
[Bitmap](#Bitmap)
This is a work in progress.[FindBitmap](#FindBitmap)
[OpenBitmap](#OpenBitmap)
[SaveBitmap](#SaveBitmap)
[TostringBitmap](#TostringBitmap)
[GetPortion](#GetPortion)
[Convert](#Convert)
[FreeBitmap](#FreeBitmap)
[ReadBitmap](#ReadBitmap)
[CopyBitpb](#CopyBitpb)
[DeepCopyBit](#DeepCopyBit)
[Event](#Event)
[AddEvent](#AddEvent)
[StopEvent](#StopEvent)
[Window](#Window)
This is a work in progress.[ShowAlert](#ShowAlert)
[CloseWindow](#CloseWindow)
[IsValid](#IsValid)
[SetActive](#SetActive)
[GetActive](#GetActive)
[SetHandle](#SetHandle)
[GetHandle](#GetHandle)
[GetTitle](#GetTitle)
[GetPID](#GetPID)
[Pids](#Pids)
[PidExists](#PidExists)
[Process](#Process)
[FindName](#FindName)
[FindNames](#FindNames)
[FindIds](#FindIds)
[ActivePID](#ActivePID)
.GetVersion()
Get robotgo versionKeyboard
.SetKeyDelay(ms)
Sets the delay in milliseconds to sleep after a keyboard event. This is 10ms by default.Arguments:
ms - Time to sleep in milliseconds..KeyTap(key, modifier)
Press a single key.Arguments:
key - See keys.
modifier (optional, string or array) - Accepts alt, command (win), control, and shift.
Examples:
robotgo.KeyTap("h", "command")
robotgo.KeyTap("i", "alt", "command")
arr := []string{"alt", "command"}
robotgo.KeyTap("i", arr).KeyToggle(key, down, modifier)
Hold down or release a key.Arguments:
key - See keys.
down - Accepts 'down' or 'up'.
modifier (optional, string or array) - Accepts alt, command (mac), control, and shift.
Return:
return KeyToggle status.TypeStr(string)
Arguments:
string - The string to send..TypeStrDelay(string, cpm)
Arguments:
string - The string to send.
cpm - Characters per minute..WriteAll(text string)
Arguments:
text stringReturn:
.ReadAll()
Arguments:
Return:
text,
errorMouse
.SetMouseDelay(ms)
Sets the delay in milliseconds to sleep after a mouse event. This is 10ms by default.Arguments:
ms - Time to sleep in milliseconds..MoveMouse(x, y)
Moves mouse to x, y instantly, with the mouse button up.Arguments:
x, yExamples:
// Move the mouse to 100, 100 on the screen.
robotgo.MoveMouse(100, 100).MoveMouseSmooth(x, y)
Moves mouse to x, y human like, with the mouse button up.Arguments:
x, y
lowspeed, highspeedExamples:
robotgo.MoveMouseSmooth(100, 200)
robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0).MouseClick(button, double)
Clicks the mouse.Arguments:
button (optional) - Accepts "left", "right", or "center". Defaults to left.
double (optional) - Set to true to perform a double click. Defaults to false.Examples:
robotgo.MouseClick()
robotgo.MouseClick("left", true).MoveClick(x, y, button, double)
Move and click the mouse.Arguments:
x,
y,
button (optional) - Accepts "left", "right", or "center". Defaults to left.
double (optional) - Set to true to perform a double click. Defaults to false.Examples:
robotgo.MoveClick(10, 20)
robotgo.MoveClick(10, 20, "left", true).MouseToggle(down, button)
Toggles mouse button.Arguments:
down (optional) - Accepts down or up. Defaults to down.
button (optional) - Accepts "left", "right", or "center". Defaults to left.Examples:
robotgo.MouseToggle("down")
robotgo.MouseToggle("down", "right").DragMouse(x, y)
Moves mouse to x, y instantly, with the mouse button held down.Arguments:
x, yExamples:
// Mouse down at 0, 0 and then drag to 100, 100 and release.
robotgo.MoveMouse(0, 0)
robotgo.MouseToggle("down")
robotgo.DragMouse(100, 100)
robotgo.MouseToggle("up").GetMousePos()
Gets the mouse coordinates.Return:
Returns an object with keys x and y.Examples:
x,y := robotgo.GetMousePos()
fmt.Println("pos:", x, y).ScrollMouse(magnitude, direction)
Scrolls the mouse either up or down.Arguments:
magnitude - The amount to scroll.
direction - Accepts down or up.Examples:
robotgo.ScrollMouse(50, "up")
robotgo.ScrollMouse(50, "down")Screen
.GetPixelColor(x, y)
Gets the pixel color at x, y. This function is perfect for getting a pixel or two,
but if you'll be reading large portions of the screen use screen.capture.Arguments:
x, yReturn:
Returns the hex color code of the pixel at x, y..GetScreenSize()
Gets the screen width and height.Return:
Returns an object with .width and .height..CaptureScreen
// CaptureScreen
Gets part or all of the screen.
GoCaptureScreen Returns a go structArguments:
x (optional)
y (optional)
height (optional)
width (optional)
If no arguments are provided, capturescreen(screencapture) will get the full screen.Return:
Returns a bitmap object.Bitmap
This is a work in progress..FindBitmap
find bitmap.Arguments:
bitmap;
rect(optional): x, y, w, hReturn:
Returns a position x and y.OpenBitmap
open bitmap.Arguments:
bitmap image path,
MMImageType (optional)Return:
Returns a bitmap.SaveBitmap
Save a image with bitmap.Arguments:
bitmap,
path,
imagetype (int)Return:
return save image status.TostringBitmap
bitmap to stringArguments:
bitmapReturn:
Return a sting bitmap.GetPortion
bitmap from a portionArguments:
bitmap,
rect: x, y, w, hReturn:
Returns new bitmap object created from a portion of another.Convert(openpath, savepath, MMImageType)
Convert the image formatArguments:
openpath,
savepath,
MMImageType (optional)Examples:
robotgo.Convert("test.png", "test.tif").FreeBitmap(MMBitmapRef)
FreeBitmap free and dealloc bitmapArguments:
MMBitmapRefExamples:
robotgo.FreeBitmap(bitmap).ReadBitmap(MMBitmapRef)
ReadBitmap returns false and sets error if |bitmap| is NULLArguments:
MMBitmapRefReturn:
boolExamples:
robotgo.ReadBitmap(bitmap).CopyBitpb(MMBitmapRef)
CopyBitpb copy bitmap to pasteboard
Arguments:
MMBitmapRefReturn:
boolExamples:
robotgo.CopyBitpb(bitmap).DeepCopyBit(MMBitmapRef)
DeepCopyBit deep copy bitmap
Arguments:
MMBitmapRefReturn:
MMBitmapRefExamples:
robotgo.DeepCopyBit(bitmap)Event
.AddEvent(string)
Listening global eventArguments:
string
(mouse arguments: mleft, mright, wheelDown, wheelUp, wheelLeft, wheelRight)Return:
if listened return 0Examples:
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
keve := robotgo.AddEvent("k")
if keve {
fmt.Println("you press...", "k")
}
mleft := robotgo.AddEvent("mleft")
if mleft {
fmt.Println("you press...", "mouse left button")
}
}.StopEvent()
stop listen global eventWindow
.ShowAlert(title, msg, defaultButton, cancelButton string)
Displays alert with the given attributes. If cancelButton is not given, only the defaultButton is displayedArguments:
title (string),
msg (string),
defaultButton (optional string),
cancelButton (optional string)Return:
Returns 0(True) if the default button was pressed, or 1(False) if cancelled..CloseWindow()
Close the WindowArguments:
NoneReturn:
None.IsValid()
Valid the WindowArguments:
NoneReturn:
Returns true if a window has been selected.SetActive()
Set the Active Window
Arguments:
hwndReturn:
void.GetActive()
Get the Active WindowArguments:
NoneReturn:
Returns hwnd.SetHandle()
Set the Window HandleArguments:
intReturn:
bool.GetHandle()
Get the Window HandleArguments:
NoneReturn:
Returns hwnd.GetTitle()
Get the Window TitleArguments:
NoneReturn:
Returns Window Title.GetPID()
Get the process idArguments:
NoneReturn:
Returns the process id.Pids()
Pids get the all process idArguments:
NoneReturn:
Returns all process id.PidExists()
PidExists determine whether the process existsArguments:
pidReturn:
Returns bool.Process()
Process get the all process struct
Arguments:
noneReturn:
Returns []Nps, error.FindName()
FindName find the process name by the process idArguments:
pidReturn:
Returns string, error.FindNames()
FindNames find the all process nameArguments:
noneReturn:
Returns []string, error.FindIds()
FindIds find the process id by the process nameArguments:
name stringReturn:
Returns []int32, error.ActivePID()
ActivePID window active by PIDArguments:
pid int32Return:
noneArchive Doc Zh (`docs/archive/doc_zh.md`)
方法:
[GetVersion](#GetVersion)
[键盘](#Keyboard)
[Keys](https://github.com/go-vgo/robotgo/blob/master/docs/keys.md)
[SetKeyDelay](#SetKeyDelay)
[KeyTap](#KeyTap)
[KeyToggle](#KeyToggle)
[TypeStr](#TypeStr)
[TypeStrDelay](#TypeStrDelay)
[WriteAll](#WriteAll)
[ReadAll](#ReadAll)
[鼠标](#Mouse)
[SetMouseDelay](#SetMouseDelay)
[MoveMouse](#MoveMouse)
[Move](#MoveMouse) (相当于 MoveMouse)
[MoveMouseSmooth](#MoveMouseSmooth)
[MoveSmooth](#MoveMouseSmooth) (相当与 MoveMouseSmooth)
[MouseClick](#MouseClick)
[Click](#MouseClick) (相当于 MouseClick)
[MoveClick](#MoveClick)
[MouseToggle](#MouseToggle)
[DragMouse](#DragMouse)
[Drag](#DragMouse) (相当于 DragMouse)
[GetMousePos](#GetMousePos)
[ScrollMouse](#ScrollMouse)
.GetVersion()
获取 robotgo 版本[屏幕](#Screen)
[GetPixelColor](#GetPixelColor)
[GetScreenSize](#GetScreenSize)
[CaptureScreen](#CaptureScreen)
[GetXDisplayName(Linux)](#GetXDisplayName)
[SetXDisplayName(Linux)](#SetXDisplayName)
[位图](#Bitmap)
This is a work in progress. (工作正在进行中)[FindBitmap](#FindBitmap)
[OpenBitmap](#OpenBitmap)
[SaveBitmap](#SaveBitmap)
[TostringBitmap](#TostringBitmap)
[GetPortion](#GetPortion)
[Convert](#Convert)
[FreeBitmap](#FreeBitmap)
[ReadBitmap](#ReadBitmap)
[CopyBitpb](#CopyBitpb)
[DeepCopyBit](#DeepCopyBit)
[事件](#Event)
[AddEvent](#AddEvent)
[StopEvent](#StopEvent)
[窗口](#Window)
This is a work in progress.[ShowAlert](#ShowAlert)
[CloseWindow](#CloseWindow)
[IsValid](#IsValid)
[SetActive](#SetActive)
[GetActive](#GetActive)
[SetHandle](#SetHandle)
[GetHandle](#GetHandle)
[GetTitle](#GetTitle)
[GetPID](#GetPID)
[Pids](#Pids)
[PidExists](#PidExists)
[Process](#Process)
[FindName](#FindName)
[FindNames](#FindNames)
[FindIds](#FindIds)
[ActivePID](#ActivePID)
键盘
.SetKeyDelay(ms)
设置键盘延迟 (在键盘一个事件后), 单位 ms, 默认值 10ms
Sets the delay in milliseconds to sleep after a keyboard event. This is 10ms by default.参数:
延迟时间,单位 ms
ms - Time to sleep in milliseconds..KeyTap(key, modifier)
模拟键盘按键
Press a single key.参数:
键盘值
修饰值 (可选类型, 字符串或者数组) - 可选值: alt, command (win), control, and shift.key - See keys.
modifier (optional, string or array) - Accepts alt, command (win), control, and shift.
示例:
robotgo.KeyTap("h", "command")
robotgo.KeyTap("i", "alt", "command")
arr := []string{"alt", "command"}
robotgo.KeyTap("i", arr).KeyToggle(key, down, modifier)
键盘切换, 按住或释放一个键位
Hold down or release a key.参数:
key - See keys.
down - Accepts 'down' or 'up'.
modifier (optional, string or array) - Accepts alt, command (mac), control, and shift.
返回值:
返回 KeyToggle 状态.TypeStr(string)
参数:
string - The string to send..TypeStrDelay(string, cpm)
参数:
string - The string to send.
cpm - Characters per minute..WriteAll(text string)
参数:
text string返回值:
.ReadAll()
参数:
返回值:
text,
error鼠标
.SetMouseDelay(ms)
设置鼠标延迟 (在一个鼠标事件后), 单位 ms, 默认值 10 ms
Sets the delay in milliseconds to sleep after a mouse event. This is 10ms by default.参数:
ms - Time to sleep in milliseconds..MoveMouse(x, y)
移动鼠标
Moves mouse to x, y instantly, with the mouse button up.参数:
x, y示例:
// Move the mouse to 100, 100 on the screen.
robotgo.MoveMouse(100, 100).MoveMouseSmooth(x, y)
模拟鼠标向 X,Y 平滑移动(像人类一样),用鼠标按钮向上
Moves mouse to x, y human like, with the mouse button up.参数:
x, y
lowspeed, highspeed示例:
robotgo.MoveMouseSmooth(100, 200)
robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0).MouseClick(button, double)
鼠标点击
Clicks the mouse.参数:
button (optional) - Accepts left, right, or center. Defaults to left.
double (optional) - Set to true to perform a double click. Defaults to false.示例:
robotgo.MouseClick()
robotgo.MouseClick("left", true).MoveClick(x, y, button, double)
移动并点击鼠标参数:
x,
y,
button (optional) - Accepts "left", "right", or "center". Defaults to left.
double (optional) - Set to true to perform a double click. Defaults to false.示例:
robotgo.MoveClick(10, 20)
robotgo.MoveClick(10, 20, "left", true).MouseToggle(down, button)
鼠标切换
Toggles mouse button.参数:
down (optional) - Accepts down or up. Defaults to down.
button (optional) - Accepts "left", "right", or "center". Defaults to left.示例:
robotgo.MouseToggle("down")
robotgo.MouseToggle("down", "right").DragMouse(x, y)
拖动鼠标
Moves mouse to x, y instantly, with the mouse button held down.参数:
x, y示例:
// Mouse down at 0, 0 and then drag to 100, 100 and release.
robotgo.MoveMouse(0, 0)
robotgo.MouseToggle("down")
robotgo.DragMouse(100, 100)
robotgo.MouseToggle("up").GetMousePos()
获取鼠标的位置
Gets the mouse coordinates.返回值:
Returns an object with keys x and y.示例:
x, y := robotgo.GetMousePos()
fmt.Println("pos:", x, y).ScrollMouse(magnitude, direction)
滚动鼠标
Scrolls the mouse either up or down.参数:
滚动位置的大小
滚动方向: up (向上滚动) down (向下滚动)
magnitude - The amount to scroll.
direction - Accepts down or up.示例:
robotgo.ScrollMouse(50, "up")
robotgo.ScrollMouse(50, "down")屏幕
.GetPixelColor(x, y)
获取坐标为 x, y 位置处的颜色
Gets the pixel color at x, y. This function is perfect for getting a pixel or two,
but if you'll be reading large portions of the screen use screen.capture.参数:
x, y返回值:
Returns the hex color code of the pixel at x, y..GetScreenSize()
获取屏幕大小
Gets the screen width and height.返回值:
Returns an object with .width and .height..CaptureScreen
// CaptureScreen
获取部分或者全部屏幕
Gets part or all of the screen.
GoCaptureScreen Returns a go struct参数:
x (optional)
y (optional)
height (optional)
width (optional)
If no arguments are provided, capturescreen(screencapture) will get the full screen.返回值:
返回一个 bitmap object.位图
This is a work in progress..FindBitmap
查找 bitmap.参数:
bitmap;
rect (可选参数): x, y, w, hReturn:
查找到, 返回 bitmap 的 x 和y 坐标; 没有返回 nil.OpenBitmap
打开 bitmap 图片.参数:
bitmap 图片路径,
MMImageType (可选)返回值:
返回一个 bitmap 对象.SaveBitmap
保存一个 bitmap 图片.参数:
bitmap 对象,
保存路径,
imagetype (int)返回值:
保存图片, 返回保存状态.TostringBitmap
将一个 bitmap 对象转换为字符串对象.参数:
bitmap 对象Return:
返回一个 bitmap 字符串.GetPortion
bitmap from a portion参数:
bitmap,
rect: x, y, w, h返回值:
Returns new bitmap object created from a portion of another.Convert(openpath, savepath, MMImageType)
转换 bitmap 图片格式参数:
openpath,
savepath,
MMImageType (可选)示例:
robotgo.Convert("test.png", "test.tif").FreeBitmap(MMBitmapRef)
FreeBitmap free and dealloc bitmap参数:
MMBitmapRef示例:
robotgo.FreeBitmap(bitmap).ReadBitmap(MMBitmapRef)
ReadBitmap returns false and sets error if |bitmap| is NULL参数:
MMBitmapRef返回值:
bool示例:
robotgo.ReadBitmap(bitmap).CopyBitpb(MMBitmapRef)
CopyBitpb copy bitmap to pasteboard
参数:
MMBitmapRef返回值:
bool示例:
robotgo.CopyBitpb(bitmap).DeepCopyBit(MMBitmapRef)
DeepCopyBit deep copy bitmap
参数:
MMBitmapRef返回值:
MMBitmapRef示例:
robotgo.DeepCopyBit(bitmap)事件
.AddEvent(string)
监听全局事件参数:
string
(鼠标参数: mleft, mright, wheelDown, wheelUp, wheelLeft, wheelRight)返回值:
监听成功返回 0示例:
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
keve := robotgo.AddEvent("k")
if keve {
fmt.Println("you press...", "k")
}
mleft := robotgo.AddEvent("mleft")
if mleft {
fmt.Println("you press...", "mouse left button")
}
}.StopEvent()
停止事件监听窗口
.ShowAlert(title, msg, defaultButton, cancelButton string)
Displays alert with the given attributes. If cancelButton is not given, only the defaultButton is displayed参数:
title (string),
msg (string),
defaultButton (optional string),
cancelButton (optional string)返回值:
Returns 0 (True) if the default button was pressed, or 1 (False) if cancelled..CloseWindow()
关闭窗口参数:
无返回值:
无.IsValid()
Valid the Window参数:
无返回值:
如果窗口 selected 返回 true.SetActive()
设为当前窗口参数:
hwnd返回值:
void.GetActive()
获取当前窗口参数:
无返回值:
Returns hwnd.SetHandle()
Set the Window Handle参数:
int返回值:
bool.GetHandle()
获取窗口 Handle参数:
无返回值:
Returns hwnd.GetTitle()
获取窗口标题参数:
返回值:
返回窗口标题.GetPID()
获取进程 id参数:
无返回值:
返回进程 id.Pids()
获取所有进程 id参数:
无返回值:
返回进程 id.PidExists()
判断进程 id 是否存在参数:
pid返回值:
返回 bool.Process()
Process get the all process struct
参数:
无返回值:
Returns []Nps, error.FindName()
FindName find the process name by the process id参数:
pid返回值:
Returns string, error.FindNames()
FindNames find the all process nameArguments:
noneReturn:
Returns []string, error.FindIds()
FindIds find the process id by the process nameArguments:
name stringReturn:
Returns []int32, error.ActivePID()
ActivePID window active by PIDArguments:
pid int32Return:
none--- METRICS ---
- Files Extracted: 10
- Estimated Token Budget: ~21765 tokens
- Canonical Reference: https://codewiki.google/github.com/go-vgo/robotgo