2017-03-14 10:07:12 +00:00
# Robotgo
2018-09-22 13:41:33 +00:00
2016-12-09 14:08:55 +00:00
<!-- <img align="right" src="https://raw.githubusercontent.com/go - vgo/robotgo/master/logo.jpg"> -->
2016-12-09 15:24:26 +00:00
<!-- [](https://travis - ci.org/go - vgo/robotgo)
2016-12-10 15:33:09 +00:00
[](https://codecov.io/gh/go-vgo/robotgo)-->
2017-01-05 09:51:08 +00:00
<!-- <a href="https://circleci.com/gh/go - vgo/robotgo/tree/dev"><img src="https://img.shields.io/circleci/project/go - vgo/robotgo/dev.svg" alt="Build Status"></a> -->
2019-12-07 18:24:47 +00:00
[](https://github.com/go-vgo/robotgo/commits/master)
2017-01-05 09:51:08 +00:00
[](https://circleci.com/gh/go-vgo/robotgo)
2019-12-07 18:24:47 +00:00
[](https://travis-ci.org/go-vgo/robotgo)
2017-12-11 09:40:55 +00:00

2016-12-10 15:33:09 +00:00
[](https://goreportcard.com/report/github.com/go-vgo/robotgo)
2016-12-10 12:07:25 +00:00
[](https://godoc.org/github.com/go-vgo/robotgo)
2018-09-22 13:32:44 +00:00
[](https://github.com/go-vgo/robotgo/releases/latest)
2017-01-06 09:29:47 +00:00
[](https://gitter.im/go-vgo/robotgo?utm_source=badge& utm_medium=badge& utm_campaign=pr-badge& utm_content=badge)
2018-09-22 13:32:44 +00:00
<!-- [](https://github.com/go-vgo/robotgo/releases/latest) -->
<!-- <a href="https://github.com/go - vgo/robotgo/releases"><img src="https://img.shields.io/badge/%20version%20 - %206.0.0%20 - blue.svg?style=flat - square" alt="Releases"></a> -->
2019-01-09 00:11:01 +00:00
2017-03-04 16:04:38 +00:00
>Golang Desktop Automation. Control the mouse, keyboard, bitmap, read the screen, Window Handle and global event listener.
2019-01-09 00:11:01 +00:00
2016-10-06 11:39:35 +00:00
RobotGo supports Mac, Windows, and Linux(X11).
2016-10-06 10:49:18 +00:00
2019-07-11 15:37:20 +00:00
[Chinese Simplified ](https://github.com/go-vgo/robotgo/blob/master/README_zh.md )
2017-02-28 12:58:16 +00:00
2017-03-14 10:07:12 +00:00
## Contents
2017-01-24 15:27:47 +00:00
- [Docs ](#docs )
2019-03-11 14:22:10 +00:00
- [Binding ](#binding )
2017-01-20 14:18:57 +00:00
- [Requirements ](#requirements )
2017-01-17 12:52:42 +00:00
- [Installation ](#installation )
- [Update ](#update )
- [Examples ](#examples )
2018-08-03 12:08:11 +00:00
- [Cross-Compiling ](#crosscompiling )
2018-09-06 14:48:50 +00:00
- [Authors ](#authors )
2017-03-17 12:18:50 +00:00
- [Plans ](#plans )
2017-03-17 12:27:34 +00:00
- [Donate ](#donate )
2017-01-17 12:52:42 +00:00
- [Contributors ](#contributors )
2017-03-17 06:35:56 +00:00
- [License ](#license )
2016-10-08 12:51:52 +00:00
2017-03-14 10:07:12 +00:00
## Docs
2018-07-04 13:02:45 +00:00
- [GoDoc ](https://godoc.org/github.com/go-vgo/robotgo )
2017-03-17 12:27:34 +00:00
- [API Docs ](https://github.com/go-vgo/robotgo/blob/master/docs/doc.md )
2019-07-11 02:47:37 +00:00
- [Chinese Docs ](https://github.com/go-vgo/robotgo/blob/master/docs/doc_zh.md )
2017-01-24 15:16:12 +00:00
2019-03-11 14:22:10 +00:00
## Binding:
[Robotn ](https://github.com/vcaesar/robotn ), binding JavaScript and other, support more language.
2017-03-14 10:07:12 +00:00
## Requirements:
2017-01-24 15:16:12 +00:00
2018-11-08 17:57:00 +00:00
Now, Please make sure `Golang, GCC` is installed correctly before installing RobotGo.
2016-10-06 12:56:00 +00:00
2019-01-09 00:11:01 +00:00
### ALL:
```
2017-01-14 11:59:40 +00:00
Golang
2017-12-08 18:32:23 +00:00
2017-01-24 15:27:47 +00:00
GCC
2017-01-14 11:59:40 +00:00
```
2018-12-21 16:07:27 +00:00
2017-03-14 10:07:12 +00:00
#### For Mac OS X:
2017-01-14 11:59:40 +00:00
```
2017-12-08 18:22:06 +00:00
Xcode Command Line Tools
2019-01-09 00:11:01 +00:00
```
2018-12-21 16:07:27 +00:00
2017-03-14 10:07:12 +00:00
#### For Windows:
2017-01-14 11:59:40 +00:00
```
2018-01-31 11:03:39 +00:00
MinGW-w64 (Use recommended) or other GCC
2017-01-14 11:59:40 +00:00
```
2018-12-21 16:07:27 +00:00
2017-03-14 10:07:12 +00:00
#### For everything else:
2019-01-08 16:51:09 +00:00
2017-01-14 11:59:40 +00:00
```
2018-07-06 11:29:38 +00:00
GCC, libpng
2019-01-09 00:11:01 +00:00
2017-01-14 11:59:40 +00:00
X11 with the XTest extension (also known as the Xtst library)
2016-11-02 18:34:40 +00:00
2017-01-14 11:59:40 +00:00
Event:
2019-01-09 00:11:01 +00:00
2017-03-24 13:47:22 +00:00
xcb, xkb, libxkbcommon
2019-01-09 00:11:01 +00:00
```
2016-10-29 19:05:41 +00:00
2017-03-14 10:07:12 +00:00
##### Ubuntu:
2019-01-08 16:51:09 +00:00
2017-01-14 11:59:40 +00:00
```yml
2017-02-18 10:17:45 +00:00
sudo apt-get install gcc libc6-dev
2016-10-24 05:20:36 +00:00
2019-01-09 00:11:01 +00:00
sudo apt-get install libx11-dev xorg-dev libxtst-dev libpng++-dev
2016-10-29 19:05:41 +00:00
2017-01-14 11:59:40 +00:00
sudo apt-get install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev
sudo apt-get install libxkbcommon-dev
2016-10-06 11:03:22 +00:00
2018-07-06 11:20:33 +00:00
sudo apt-get install xsel xclip
2017-01-14 11:59:40 +00:00
```
2017-01-20 14:18:57 +00:00
2017-04-22 08:26:20 +00:00
#### Fedora:
```yml
sudo dnf install libxkbcommon-devel libXtst-devel libxkbcommon-x11-devel xorg-x11-xkb-utils-devel
sudo dnf install libpng-devel
2017-06-11 10:56:26 +00:00
2018-07-06 11:20:33 +00:00
sudo dnf install xsel xclip
2017-04-22 08:26:20 +00:00
```
2017-03-14 10:07:12 +00:00
## Installation:
2017-01-20 14:18:57 +00:00
```
go get github.com/go-vgo/robotgo
```
It's that easy!
2017-03-04 16:04:38 +00:00
png.h: No such file or directory? Please see [issues/47 ](https://github.com/go-vgo/robotgo/issues/47 ).
2017-02-18 10:42:04 +00:00
2017-03-14 10:07:12 +00:00
## Update:
2017-01-20 14:18:57 +00:00
```
2019-01-09 00:11:01 +00:00
go get -u github.com/go-vgo/robotgo
2017-01-20 14:18:57 +00:00
```
2018-12-21 16:07:27 +00:00
2019-01-09 00:11:01 +00:00
Note go1.10.x C file compilation cache problem, [golang #24355 ](https://github.com/golang/go/issues/24355 ).
2018-12-05 17:05:12 +00:00
`go mod vendor` problem, [golang #26366 ](https://github.com/golang/go/issues/26366 ).
2017-01-20 14:18:57 +00:00
2019-01-08 16:51:09 +00:00
2017-05-25 14:36:51 +00:00
## [Examples:](https://github.com/go-vgo/robotgo/blob/master/examples)
2016-10-06 11:03:22 +00:00
2017-06-04 14:53:47 +00:00
#### [Mouse](https://github.com/go-vgo/robotgo/blob/master/examples/mouse/main.go)
2016-10-06 11:03:22 +00:00
```Go
package main
import (
"github.com/go-vgo/robotgo"
)
func main() {
robotgo.ScrollMouse(10, "up")
2017-01-15 22:54:39 +00:00
robotgo.MouseClick("left", true)
2016-11-12 14:15:30 +00:00
robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0)
2019-01-09 00:11:01 +00:00
}
```
2016-10-06 11:10:16 +00:00
2017-06-04 14:53:47 +00:00
#### [Keyboard](https://github.com/go-vgo/robotgo/blob/master/examples/key/main.go)
2016-10-06 11:10:16 +00:00
```Go
package main
import (
2017-06-11 11:52:03 +00:00
"fmt"
2017-08-04 15:59:19 +00:00
"github.com/go-vgo/robotgo"
2016-10-06 11:10:16 +00:00
)
func main() {
2019-02-12 13:12:48 +00:00
robotgo.TypeStr("Hello World")
2019-12-16 13:32:07 +00:00
robotgo.TypeStr("だんしゃり", 1.0)
// robotgo.TypeString("テストする")
2019-01-09 00:11:01 +00:00
2019-07-11 15:37:20 +00:00
robotgo.TypeStr("Hi galaxy. こんにちは世界.")
2018-08-20 11:32:36 +00:00
robotgo.Sleep(1)
2019-01-09 00:11:01 +00:00
2019-07-11 03:03:29 +00:00
// ustr := uint32(robotgo.CharCodeAt("Test", 0))
2019-03-01 11:34:59 +00:00
// robotgo.UnicodeType(ustr)
2018-01-18 13:46:35 +00:00
2016-10-06 11:12:12 +00:00
robotgo.KeyTap("enter")
2019-03-01 11:34:59 +00:00
// robotgo.TypeString("en")
2016-11-14 10:20:43 +00:00
robotgo.KeyTap("i", "alt", "command")
2019-02-13 11:11:32 +00:00
2016-11-14 10:22:53 +00:00
arr := []string{"alt", "command"}
robotgo.KeyTap("i", arr)
2017-06-11 11:52:03 +00:00
2017-07-04 12:19:39 +00:00
robotgo.WriteAll("Test")
2017-06-11 12:14:53 +00:00
text, err := robotgo.ReadAll()
if err == nil {
fmt.Println(text)
}
2019-01-09 00:11:01 +00:00
}
2016-10-06 11:10:16 +00:00
```
2017-06-04 14:53:47 +00:00
#### [Screen](https://github.com/go-vgo/robotgo/blob/master/examples/screen/main.go)
2016-10-06 11:10:16 +00:00
```Go
package main
import (
2017-01-24 15:16:12 +00:00
"fmt"
2016-10-06 11:10:16 +00:00
"github.com/go-vgo/robotgo"
)
func main() {
x, y := robotgo.GetMousePos()
2018-11-08 17:57:00 +00:00
fmt.Println("pos: ", x, y)
2019-02-13 11:11:32 +00:00
2016-11-24 08:19:01 +00:00
color := robotgo.GetPixelColor(100, 200)
2018-11-08 17:57:00 +00:00
fmt.Println("color---- ", color)
2019-01-09 00:11:01 +00:00
}
2016-10-06 11:10:16 +00:00
```
2016-10-30 06:28:27 +00:00
2018-01-11 11:26:10 +00:00
#### [Bitmap](https://github.com/go-vgo/robotgo/blob/master/examples/bitmap/main.go)
2016-10-30 06:28:27 +00:00
```Go
package main
import (
2017-01-24 15:16:12 +00:00
"fmt"
2016-10-30 06:28:27 +00:00
"github.com/go-vgo/robotgo"
)
func main() {
2017-01-24 15:27:47 +00:00
bitmap := robotgo.CaptureScreen(10, 20, 30, 40)
2018-08-03 15:51:28 +00:00
// use `defer robotgo.FreeBitmap(bit)` to free the bitmap
defer robotgo.FreeBitmap(bitmap)
2017-01-24 15:27:47 +00:00
fmt.Println("...", bitmap)
2016-10-30 06:28:27 +00:00
2017-08-24 13:31:42 +00:00
fx, fy := robotgo.FindBitmap(bitmap)
2018-11-08 17:57:00 +00:00
fmt.Println("FindBitmap------ ", fx, fy)
2016-10-30 06:28:27 +00:00
2017-01-24 15:27:47 +00:00
robotgo.SaveBitmap(bitmap, "test.png")
2019-01-09 00:11:01 +00:00
}
2016-10-30 06:28:27 +00:00
```
2017-06-04 14:53:47 +00:00
#### [Event](https://github.com/go-vgo/robotgo/blob/master/examples/event/main.go)
2016-10-30 06:28:27 +00:00
```Go
package main
import (
2017-01-24 15:16:12 +00:00
"fmt"
2016-10-30 06:28:27 +00:00
"github.com/go-vgo/robotgo"
)
func main() {
2019-02-22 12:37:25 +00:00
ok := robotgo.AddEvents("q", "ctrl", "shift")
2019-02-22 12:42:23 +00:00
if ok {
fmt.Println("add events...")
}
2019-02-22 12:37:25 +00:00
2016-11-12 07:56:07 +00:00
keve := robotgo.AddEvent("k")
2019-02-21 14:00:10 +00:00
if keve {
2018-11-08 17:57:00 +00:00
fmt.Println("you press... ", "k")
2016-10-30 06:32:34 +00:00
}
2016-11-12 07:56:07 +00:00
mleft := robotgo.AddEvent("mleft")
2019-02-21 14:00:10 +00:00
if mleft {
2018-11-08 17:57:00 +00:00
fmt.Println("you press... ", "mouse left button")
2016-10-30 06:32:34 +00:00
}
2019-01-09 00:11:01 +00:00
}
2016-11-07 09:08:12 +00:00
```
2017-06-04 14:53:47 +00:00
#### [Window](https://github.com/go-vgo/robotgo/blob/master/examples/window/main.go)
2016-11-07 09:08:12 +00:00
```Go
package main
import (
2017-01-24 15:16:12 +00:00
"fmt"
2016-11-07 09:08:12 +00:00
"github.com/go-vgo/robotgo"
)
func main() {
2017-07-01 15:12:19 +00:00
fpid, err := robotgo.FindIds("Google")
if err == nil {
2018-11-08 17:57:00 +00:00
fmt.Println("pids... ", fpid)
2018-01-19 12:46:25 +00:00
if len(fpid) > 0 {
robotgo.ActivePID(fpid[0])
2018-02-03 09:42:38 +00:00
robotgo.Kill(fpid[0])
2018-01-19 12:46:25 +00:00
}
2017-07-01 15:12:19 +00:00
}
2018-01-19 12:46:25 +00:00
robotgo.ActiveName("chrome")
2017-07-01 15:12:19 +00:00
isExist, err := robotgo.PidExists(100)
2018-02-03 09:42:38 +00:00
if err == nil & & isExist {
2017-07-01 15:12:19 +00:00
fmt.Println("pid exists is", isExist)
2018-02-03 09:42:38 +00:00
robotgo.Kill(100)
2017-07-01 15:12:19 +00:00
}
2016-11-07 10:43:10 +00:00
abool := robotgo.ShowAlert("test", "robotgo")
if abool == 0 {
2018-11-08 17:57:00 +00:00
fmt.Println("ok@@@ ", "ok")
2016-11-07 10:43:10 +00:00
}
2016-11-09 15:11:50 +00:00
2017-01-15 22:54:39 +00:00
title := robotgo.GetTitle()
2018-11-08 17:57:00 +00:00
fmt.Println("title@@@ ", title)
2019-01-09 00:11:01 +00:00
}
2016-12-07 07:22:40 +00:00
```
2017-01-04 09:57:43 +00:00
2018-08-03 12:08:11 +00:00
## CrossCompiling
2018-08-03 12:01:41 +00:00
##### Windows64 to win32
```Go
SET CGO_ENABLED=1
SET GOARCH=386
go build main.go
```
2018-12-21 16:07:27 +00:00
2018-10-22 23:47:34 +00:00
#### Other to windows
2018-08-03 12:01:41 +00:00
```Go
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -x ./
```
2018-08-05 11:40:06 +00:00
```
2019-01-09 00:11:01 +00:00
// CC=mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\gcc.exe
2018-08-05 11:40:06 +00:00
// CXX=mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\g++.exe
```
2018-08-03 12:01:41 +00:00
2019-11-26 15:19:34 +00:00
Some discussions and questions, please see [issues/228 ](https://github.com/go-vgo/robotgo/issues/228 ), [issues/143 ](https://github.com/go-vgo/robotgo/issues/143 ).
2018-09-06 14:48:50 +00:00
## Authors
* [The author is vz ](https://github.com/vcaesar )
* [Maintainers ](https://github.com/orgs/go-vgo/people )
* [Contributors ](https://github.com/go-vgo/robotgo/graphs/contributors )
2017-03-17 12:18:50 +00:00
## Plans
2017-01-15 09:09:05 +00:00
- Update Find an image on screen, read pixels from an image
- Update Window Handle
2017-03-04 16:27:09 +00:00
- Try support Android, maybe support IOS
2017-01-15 09:09:05 +00:00
2017-03-17 12:27:34 +00:00
## Donate
2017-05-20 10:49:41 +00:00
Supporting robotgo, [buy me a coffee ](https://github.com/go-vgo/buy-me-a-coffee ).
2017-03-17 12:27:34 +00:00
2017-05-20 10:49:41 +00:00
#### Paypal
2017-05-20 10:48:10 +00:00
Donate money by [paypal ](https://www.paypal.me/veni0/25 ) to my account [vzvway@gmail.com ](vzvway@gmail.com )
2017-03-14 10:07:12 +00:00
## Contributors
2017-01-04 09:57:43 +00:00
- See [contributors page ](https://github.com/go-vgo/robotgo/graphs/contributors ) for full list of contributors.
- See [Contribution Guidelines ](https://github.com/go-vgo/robotgo/blob/master/CONTRIBUTING.md ).
2017-03-17 06:34:46 +00:00
## License
2017-06-11 10:56:26 +00:00
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.
2017-03-17 06:34:46 +00:00
See [LICENSE-APACHE ](http://www.apache.org/licenses/LICENSE-2.0 ), [LICENSE-MIT ](https://github.com/go-vgo/robotgo/blob/master/LICENSE ).