go-vgo/robotgo
À propos
RobotGo : RPA multiplateforme native en Go, automatisation de l’interface graphique, tests automatisés et utilisation de l’ordinateur. @vcaesar
IA et apprentissage automatiqueProgression mesurée des étoiles
- in 24h
- 0
- in 7 days
- -1
- in 15 days
- +4
- in 1 month
- +17
Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.
langs/README.fr.md
OriginalRobotgo
English | 简体中文 | 繁體中文 | 日本語 | 한국어 | Français | Deutsch | Español | Русский | Português
Automatisation de bureau en Golang, tests automatisés et utilisation de l'ordinateur par l'IA (Computer Use).
Contrôlez la souris et le clavier, lisez l'écran, gérez les processus, les handles de fenêtre, les images et les bitmaps, ainsi que l'écoute globale des événements.
RobotGo prend en charge Mac, Windows et Linux ; et robotgo prend en charge les architectures arm64 et x86-amd64.
Je développe actuellement Codg, un système de travail à base d'agents IA simple à utiliser : automatisé, asynchrone, concurrent, efficace et d'une grande précision.
RobotGo-Pro propose les versions JavaScript, Python, Lua et d'autres langages, le support technique, de nouvelles fonctionnalités ainsi que la toute dernière version de robotgo (« aucune version open source pour le moment »).
Sommaire
- Documentation
- Faire un don
- Binding
- Prérequis
- Builds sans Cgo
- Installation
- Mise à jour
- Exemples
- Conversion de types et touches
- Compilation croisée
- Auteurs
- Projets
- Licence
Docs
- GoDoc
- Documentation de l'API (obsolète, plus mise à jour)
Donate
Donateurs, sponsors ou autres, contact : [email protected]
Binding
ADB, encapsulation d'adb Android et de WDA iOS, avec une API compatible robotgo.
Requirements
Go 1.26+ (voir go.mod) et un backend :
- Par défaut (Cgo) :
CGO_ENABLED=1, un compilateur C et les bibliothèques système ci-dessous. - Go pur (testé) : aucune chaîne d'outils C ; voir Builds sans Cgo.
Les deux nécessitent les dépendances par fonctionnalité correspondant aux fonctionnalités utilisées.
Default Cgo setup
macOS
Go et les Xcode Command Line Tools (Clang) :
brew install go
xcode-select --install
Autorisations (Cgo et Go pur) : dans Réglages Système > Confidentialité et sécurité, accordez à l'application ou au terminal l'Accessibilité (saisie) et l'Enregistrement de l'écran (capture).
Windows
winget install GoLang.Go
Plus une chaîne d'outils C. LLVM-MinGW :
winget install MartinStorsjo.LLVM-MinGW.UCRT
$env:CC = "clang"
Ou MinGW-w64 (WinLibs) :
winget install BrechtSanders.WinLibs.POSIX.UCRT
$env:CC = "gcc"
Le répertoire bin de la chaîne d'outils (par exemple C:\mingw64\bin) doit
figurer dans PATH et correspondre à GOARCH. Tout autre compilateur compatible
Cgo, comme une installation manuelle de
MinGW-w64, fonctionne aussi.
Bitmap ne fournit libpng que pour MinGW-w64 ; avec une autre chaîne d'outils, compilez libpng vous-même.
Linux (X11)
Build : GCC, en-têtes libc, en-têtes X11/XTest. Exécution : un serveur X avec
XTEST et DISPLAY défini. Pour Wayland natif, voir Builds sans Cgo.
Ubuntu / Debian :
# Go (Snap si le paquet de la distribution est trop ancien)
sudo snap install go --classic
# ou : sudo apt install golang
# Base (Cgo) : compilateur, libc, X11, XTest
sudo apt install gcc libc6-dev libx11-dev xorg-dev libxtst-dev
# Presse-papiers (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-dev
Fedora :
# Base (Cgo) : compilateur, libc, X11, XTest
sudo dnf install gcc glibc-devel libX11-devel libXtst-devel
# Presse-papiers (X11)
sudo dnf install xsel xclip
# Bitmap : libpng
sudo dnf install libpng-devel
# GoHook : XKB (Fedora < 34 : xorg-x11-xkb-utils-devel au lieu de xkbcomp-devel)
sudo dnf install libxkbcommon-devel libxkbcommon-x11-devel xkbcomp-devel
Feature-specific dependencies
À ajouter à l'installation de base, uniquement pour les fonctionnalités utilisées :
Presse-papiers Linux (Cgo et Go pur) :
xclipouxselsous X11 ;wl-clipboardsous Wayland :sudo apt install wl-clipboard # Ubuntu / Debian sudo dnf install wl-clipboard # FedoraBitmap : en-têtes libpng.
GoHook : en-têtes XCB/XKB sous Linux.
Bitmap et GoHook sont des paquets Cgo distincts ; un backend RobotGo en Go pur ne supprime pas leurs dépendances C.
Cgo-free Builds
Les backends testés en Go pur se compilent et se cross-compilent avec
CGO_ENABLED=0 (sans GCC, MinGW, Xcode ni en-têtes X11). Même chemin d'import et
même API ; un tag de build sélectionne le backend — CGO_ENABLED=0 seul ne
sélectionne rien.
GOOS cible |
Tag de build | Paquet | Prérequis d'exécution |
|---|---|---|---|
windows |
win |
win | Win32 uniquement, aucun runtime supplémentaire |
darwin |
mac |
darwin | frameworks système et autorisations de confidentialité |
linux |
x11 |
x11 | serveur X avec XTEST, DISPLAY défini |
linux |
wayland |
wayland | compositeur wlroots, voir Wayland |
linux |
libei |
libei | portail RemoteDesktop (GNOME/KDE), voir libei |
purego est un raccourci : mac sur macOS, win sur Windows, wayland sur
Linux. Ajoutez x11 ou libei pour le remplacer sous Linux (-tags "purego,x11").
Utilisez un seul tag de backend correspondant à GOOS ; les combinaisons
telles que x11,libei ne compilent pas (purego plus un remplacement Linux est
la seule exception).
Build commands
# OS courant
CGO_ENABLED=0 go build -tags purego .
# Compilation croisée
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 .
Compilez la racine du module (.) ou votre propre paquet, pas ./... :
examples/ et certains sous-paquets ont besoin d'API réservées à Cgo.
Limitations
Les prérequis d'exécution ci-dessus s'appliquent toujours. Les API réservées à
Cgo comme CaptureScreen / FreeBitmap n'existent pas ; utilisez CaptureImg.
Les opérations non prises en charge renvoient ErrNotSupported (ou un résultat
vide).
mac: pas de gestion des fenêtres —ActiveNamerenvoieErrNotSupported,GetTitlerenvoie"", et réduire/agrandir/fermer n'ont aucun effet.wayland,libei: Wayland n'a pas de protocole pour la position globale du curseur.Location()lit le vrai curseur sous Hyprland (socket IPC) et KDE Plasma (script KWin via D-Bus) lorsque cette requête réussit ;waylandexige aussi que toutes les sorties partagent le même rapport d'échelle (les sorties à échelles différentes ou pivotées se replient). Sinon, et ailleurs (GNOME, Sway, autres compositeurs wlroots), il renvoie la dernière position injectée par RobotGo, pas le curseur physique. Le presse-papiers nécessitewl-clipboard.
Wayland
Un compositeur wlroots (Sway, Hyprland, Wayfire, ...) avec WAYLAND_DISPLAY et
XDG_RUNTIME_DIR définis, exposant :
| Fonctionnalité | Global du protocole |
|---|---|
| Contrôle de la souris | zwlr_virtual_pointer_manager_v1 |
| Contrôle du clavier | zwp_virtual_keyboard_manager_v1 |
| Capture d'écran | zwlr_screencopy_manager_v1 |
| Gestion des fenêtres | zwlr_foreign_toplevel_manager_v1 |
GNOME et KDE ne fournissent pas ces protocoles ; utilisez libei dans ce cas.
libei (GNOME / KDE)
La saisie passe par l'interface D-Bus RemoteDesktop de
xdg-desktop-portal : il faut un bus de session, xdg-desktop-portal et un
backend qui l'implémente (xdg-desktop-portal-gnome, -kde ou -wlr). Au
premier lancement, une boîte de dialogue de consentement s'affiche ; le jeton de
restauration est mis en cache dans $XDG_STATE_HOME/robotgo.
Les déplacements absolus utilisent un flux ScreenCast lié (par défaut) ;
définissez libei.LinkScreenCast = false pour n'avoir que des déplacements
relatifs. La capture d'écran et la gestion des fenêtres renvoient
ErrNotSupported.
Installation
go get github.com/go-vgo/robotgo
import "github.com/go-vgo/robotgo"
png.h: No such file or directory avec Bitmap : consultez ses prérequis libpng
et issues/47.
Update
go get -u github.com/go-vgo/robotgo
Notez le problème de cache de compilation des fichiers C de go1.10.x, golang #24355.
Problème de go mod vendor, golang #26366.
Examples
Souris
package main
import (
"errors"
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
robotgo.MouseSleep = 300
robotgo.Move(100, 100)
fmt.Println(robotgo.Location())
robotgo.Move(100, -200) // multi screen supported
robotgo.MoveSmooth(120, -150)
fmt.Println(robotgo.Location())
robotgo.ScrollDir(10, "up")
robotgo.ScrollDir(20, "right")
robotgo.Scroll(0, -10)
robotgo.Scroll(100, 0)
robotgo.MilliSleep(100)
robotgo.ScrollSmooth(-10, 6)
// robotgo.ScrollRelative(10, -100)
robotgo.Move(10, 20)
robotgo.MoveRelative(0, -10)
robotgo.DragSmooth(10, 10)
robotgo.Click("wheelRight")
robotgo.Click("left", true)
robotgo.MoveSmooth(100, 200, 1.0, 10.0)
robotgo.Toggle("left")
robotgo.Toggle("left", "up")
// Vérifiez les erreurs retournées, les arguments invalides retournent une erreur
if err := robotgo.ScrollDir(10, "forward"); err != nil {
fmt.Println("robotgo.ScrollDir error:", err)
}
// Selon le backend : Cgo retourne une erreur, pur Go fait un simple clic gauche et retourne nil
if err := robotgo.Click("left", "double"); err != nil {
fmt.Println("robotgo.Click error:", err)
}
// MoveSmoothRelative signale un déplacement fluide échoué par ErrSmoothMove
err := robotgo.MoveSmoothRelative(10, -10)
if errors.Is(err, robotgo.ErrSmoothMove) {
fmt.Println("smooth move failed:", err)
}
// Les backends pur Go retournent ErrNotSupported pour les opérations non prises en charge
err = robotgo.Move(100, 200)
if errors.Is(err, robotgo.ErrNotSupported) {
fmt.Println("robotgo.Move is not supported by this backend")
}
}
Clavier
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)
}
// Un nom de touche inconnu retourne une erreur au lieu d'appuyer sur une mauvaise touche
if err := robotgo.KeyTap("notakey"); err != nil {
fmt.Println("robotgo.KeyTap error:", err)
}
// TypeStr retourne la première erreur de saisie, Type ne retourne que le nombre
if err := robotgo.TypeStr("Hello, 世界"); err != nil {
fmt.Println("robotgo.TypeStr error:", err)
}
// Maintenez un modificateur, relâchez-le toujours et vérifiez les deux erreurs
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)
}
}
}
Écran
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
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))
defer robotgo.FreeBitmap(bit2)
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
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)
}
Événement
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")
}
}
Fenêtre
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
- Meilleure prise en charge du multi-écran
- Mise à jour du handle de fenêtre
Contributors
- Consultez la page des contributeurs pour la liste complète des contributeurs.
- Consultez les directives de contribution.
License
Robotgo est principalement distribué selon les termes de « the Apache License (Version 2.0) », certaines parties étant couvertes par diverses licences de type BSD.
Voir LICENSE-APACHE, LICENSE.
Explorer des projets similaires
Chargement…